stackpanel与flipview中的省略号绑定

时间:2016-02-26 07:10:37

标签: xaml windows-phone-8.1

惠普全部!我需要一点帮助我有一个flipview,其中我使用一些包含图像和文本块的stackpanel现在我想用椭圆绑定它们。

这是我的flipview的xaml代码

  <Grid Grid.Row="1" x:Name="flipp1">
                <FlipView x:Name="flip1" HorizontalAlignment="Left" VerticalAlignment="Top" Height="auto" Width="auto" Background="#1C1C1C" BorderThickness="0,5,0,0" BorderBrush="Red" Grid.Row="1" Margin="-3">  <StackPanel Tapped="StackPanel_Tapped_1">
                        <Grid>
                            <Image x:Name="caredi" Source="Assets/images/editcars.png" Height="30" Width="30" Margin="340,15,55,170" Tapped="caredit_Tapped"></Image>
                            <Image Source ="Assets/images/logosmall.png" HorizontalAlignment="Left" Height="100" VerticalAlignment="Top" Width="100" Margin="26,27,0,0"/>
                            <Image Source ="Assets/car2.png" HorizontalAlignment="Right" VerticalAlignment="Center" Stretch="None" Margin="0,40,25,30" />
                            <RichTextBlock Foreground="Gray" FontSize="15" HorizontalAlignment="Left" Height="66" VerticalAlignment="Center" Width="197" Margin="26,120,0,0">
                                <Paragraph>
                                    <Run Text="Car Model : Toyota XLI  Reg No: Karachi Last vist : 18/dex/2015"/>
                                </Paragraph>
                            </RichTextBlock>
                        </Grid>
                    </StackPanel>        
                      <StackPanel Tapped="StackPanel_Tapped_1">
                            <Grid>
                                <Image x:Name="caredit" Source="Assets/images/editcars.png" Height="30" Width="30" Margin="340,15,55,170" Tapped="caredit_Tapped"></Image>
                                <Image Source ="Assets/images/logosmall.png" HorizontalAlignment="Left" Height="100" VerticalAlignment="Top" Width="100" Margin="36,27,0,0"/>
                                <Image Source ="Assets/car2.png" HorizontalAlignment="Right" VerticalAlignment="Center" Stretch="None" Margin="0,40,45,30" />
                                <RichTextBlock Foreground="Gray" FontSize="15" HorizontalAlignment="Left" Height="66" VerticalAlignment="Top" Width="197" Margin="36,134,0,0">
                                    <Paragraph>
                                        <Run Text="Car Model : Toyota XLI  Reg No: Karachi Last vist : 18/dex/2015"/>
                                    </Paragraph>
                                </RichTextBlock>
                            </Grid>
                       </StackPanel<Flipview></Grid>

列表框中省略号的代码

 <ListBox x:Name="ContextControl1" Height="20" VerticalAlignment="Bottom" SelectedItem="{Binding SelectedItem, ElementName=flip1, Mode=TwoWay}" Style="{StaticResource ListBoxStyle1}" ItemContainerStyle="{StaticResource ContextControlItemStyle}" Background="{x:Null}">
                    <ListBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center"/>
                        </ItemsPanelTemplate>
                    </ListBox.ItemsPanel>
                </ListBox> 

如何将这些绑定到flipview中移动,如图所示?

enter image description here

2 个答案:

答案 0 :(得分:0)

我希望你在winodws手机上运行它8.你必须使用工具包中的flipview(here)和nuget package here

<强>&LT;&LT; ------ ----更新&GT;&GT;

Banner.cs

 public  class Banner
    {
        public string Url1 { get; set; }
        public string Url2 { get; set; }
        public string Title { get; set; }
   public Banner(string url1,string url2,string title)
    {
        Url1 = url1;
        Url2 = url2;
        Title = title;
    }
    }

在xaml.cs中

  public ObservableCollection<Banner> List{get;set;}
List = new  ObservableCollection<Banner>();
    List.Add(new Banner("Assets/images/editcars.png","Assets/images/editcars.png","text"));
    List.Add(new Banner("Assets/images/editcars.png","Assets/images/editcars.png","text")); 

    <FlipView x:Name="flip1" HorizontalAlignment="Left" VerticalAlignment="Top" Height="auto" Width="auto" Background="#1C1C1C" BorderThickness="0,5,0,0" BorderBrush="Red" Grid.Row="1" Margin="-3" ItemSource={Binding List}> 

<StackPanel Tapped="StackPanel_Tapped_1">                       
                            <Image x:Name="caredi" Source="{Binding Url1}" Height="30" Width="30" Margin="340,15,55,170" Tapped="caredit_Tapped"></Image>
                            <Image Source ="{Binding Url2}" HorizontalAlignment="Left" Height="100" VerticalAlignment="Top" Width="100" Margin="26,27,0,0"/>

                            <RichTextBlock Foreground="Gray" FontSize="15" HorizontalAlignment="Left" Height="66" VerticalAlignment="Center" Width="197" Margin="26,120,0,0">
                                <Paragraph>
                                    <Run Text="{Binding Title}"/>
                                </Paragraph>
                            </RichTextBlock>                    
                    </StackPanel>                                                 
                      <Flipview>

ellpise代码

<ListBox x:Name="ContextControl1" ItemSource={Binding List} Height="20" VerticalAlignment="Bottom" SelectedItem="{Binding SelectedItem, ElementName=flip1, Mode=TwoWay}" Style="{StaticResource ListBoxStyle1}" ItemContainerStyle="{StaticResource ContextControlItemStyle}" Background="{x:Null}">
                    <ListBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center"/>
                        </ItemsPanelTemplate>
                    </ListBox.ItemsPanel>
                </ListBox> 

Indicator.xaml如下

<UserControl x:Class="MyDeals.UserControls.Indicator"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         mc:Ignorable="d"
         FontFamily="{StaticResource PhoneFontFamilyNormal}"
         FontSize="{StaticResource PhoneFontSizeNormal}"
         Foreground="{StaticResource PhoneForegroundBrush}"
         Height="12"
         d:DesignHeight="480" d:DesignWidth="480">
<Grid x:Name="LayoutRoot" >
    <StackPanel Name="IndicatorPanel" Orientation="Horizontal" />
</Grid>

Indicator.xaml.cs

    using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;

namespace MyDeals.UserControls
{
    public partial class Indicator : UserControl
    {
        /// <summary>
        /// Public ItemsCount property of type DependencyProperty
        /// </summary>
        public static readonly DependencyProperty ItemsCountProperty =
        DependencyProperty.Register("ItemsCount",
            typeof(int),
            typeof(Indicator),
            new PropertyMetadata(OnItemsCountChanged));

        /// <summary>
        /// Public SelectedPivotIndex property of type DependencyProperty
        /// </summary>
        public static readonly DependencyProperty SelectedPivotIndexProperty =
        DependencyProperty.Register("SelectedPivotIndex",
            typeof(int),
            typeof(Indicator),
            new PropertyMetadata(OnPivotIndexChanged));

        /// <summary>
        /// Constructor
        /// </summary>
        public Indicator()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Gets or sets number of pivot items
        /// </summary>
        public int ItemsCount
        {
            set { SetValue(ItemsCountProperty, value); }
            get { return (int)GetValue(ItemsCountProperty); }
        }

        /// <summary>
        /// Gets or sets index of selected pivot item
        /// </summary>
        public int SelectedPivotIndex
        {
            set { SetValue(SelectedPivotIndexProperty, value); }
            get { return (int)GetValue(SelectedPivotIndexProperty); }
        }

        /// <summary>
        /// OnItemsCountChanged property-changed handler 
        /// </summary>
        private static void OnItemsCountChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            (obj as Indicator).SetRectangles();
        }

        /// <summary>
        /// OnPivotIndexChanged property-changed handler 
        /// </summary>
        private static void OnPivotIndexChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            (obj as Indicator).AccentRectangle();
        }

        /// <summary>
        /// Draws rectangles.
        /// </summary>
        private void SetRectangles()
        {
            IndicatorPanel.Children.Clear();
            for (int i = 0; i < this.ItemsCount; i++)
            {
                Ellipse ellipse = new Ellipse()
                {
                    Height = 9,
                    Width = 9,
                    Margin = new Thickness(6, 0, 0, 0)
                };
                //Rectangle rectangle = new Rectangle() { Height = 9, Width = 9, Margin = new Thickness(4, 0, 0, 0) };
                IndicatorPanel.Children.Add(ellipse);
            }
            this.AccentRectangle();
        }

        /// <summary>
        /// Accents selected pivot item rectangle.
        /// </summary>
        private void AccentRectangle()
        {
            int i = 0;
            foreach (var item in IndicatorPanel.Children)
            {
                if (item is Ellipse)
                {
                    Ellipse ellipse = (Ellipse)item;
                    if (i == this.SelectedPivotIndex)
                        ellipse.Fill = new SolidColorBrush(Colors.Red);
                    else
                        ellipse.Fill = new SolidColorBrush(Colors.Gray);
                    i++;
                }
            }
        }
    }
}

ATBBanners是itemource和ATBCount你必须绑定

在Winodws phone 8.1中有一个名为flipview的内置控件

答案 1 :(得分:0)

为便于解决,请执行以下更改:

  1. 将您的项目添加到FlipViewItem中的stackpanels。
  2. 更改SelectedIndex以滚动到特定的flipviewitem。