找回密码
 立即注册

QQ登录

只需一步,快速开始

feiyan0320

中级会员

17

主题

70

帖子

615

积分

中级会员

积分
615

活字格认证微信认证勋章

QQ

[已处理] tile绑定数据

feiyan0320
中级会员   /  发表于:2015-10-13 13:56  /   查看:12799  /  回复:14


hi,数据不知如何绑定,请求帮忙

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

14 个回复

倒序浏览
Alice
社区贡献组   /  发表于:2015-10-13 14:49:00
沙发
回复 1楼feiyan0320的帖子

感谢提供的Demo,你的问题已经收到了。
我们验证下你的Demo后给你回复。
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2015-10-13 15:35:00
板凳
回复 1楼feiyan0320的帖子

你可以将一个ObservableCollection集合绑定给C1SlideTile。
将类实例化并且添加到ObservableCollection集合,并且通过C1SldeTile的ContentSource设置ObservableCollection集合。并且在C1SlideTile.ContentTemplate里进行类的字段的绑定。

如下是一个简单的working sample,供你参考:
CS代码:
  1. public partial class TileTypes : UserControl
  2. {
  3.     // the sample collection to use as ContentSource
  4.     public ObservableCollection<object> CustomObjects
  5.     {
  6.         get;
  7.         set;
  8.     }
  9.     public TileTypes()
  10.     {
  11.         CustomObjects = new ObservableCollection<object>();
  12.         CustomObjects.Add(new CustomObject() { Header = "object 1", Background= new SolidColorBrush(Colors.OliveDrab) });
  13.         CustomObjects.Add(new CustomObject() { Header = "object 2", Background = new SolidColorBrush(Colors.Green) });
  14.         CustomObjects.Add(new CustomObject() { Header = "object 3", Background = new SolidColorBrush(Colors.GreenYellow) });
  15.         CustomObjects.Add(new CustomObject() { Header = "object 4", Background = new SolidColorBrush(Colors.White) });
  16.         CustomObjects.Add(new CustomObject() { Header = "object 5", Background = new SolidColorBrush(Colors.Navy) });
  17.         CustomObjects.Add(new CustomObject() { Header = "object 6", Background = new SolidColorBrush(Colors.Olive) });

  18.         InitializeComponent();
  19.     }
  20. }

  21. public class CustomObject
  22. {
  23.     public string Header
  24.     {
  25.         get;
  26.         set;
  27.     }
  28.     public Brush Background
  29.     {
  30.         get;
  31.         set;
  32.     }
  33. }
复制代码

XAML代码:
  1. <c1:C1SlideTile ContentSource="{Binding CustomObjects, ElementName=root}" Header="ContentSource"
  2.                 VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" >
  3.     <c1:C1SlideTile.ContentTemplate>
  4.         <DataTemplate>
  5.             <Grid Background="{Binding Background}">
  6.                 <TextBlock Text="{Binding Header}"
  7.                            VerticalAlignment="Center" HorizontalAlignment="Center"
  8.                            FontSize="18" Foreground="Tomato"/>
  9.             </Grid>
  10.         </DataTemplate>
  11.     </c1:C1SlideTile.ContentTemplate>
  12. </c1:C1SlideTile>
复制代码
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
feiyan0320
中级会员   /  发表于:2015-10-13 17:02:00
地板
回复 3楼Alice的帖子

其实我主要是在一个itemcontrol里套了一个tile,我把一个ObservableCollection给了itemcontrol,然后tile里怎么绑定就不知道了,
是一个ObservableCollection里面再套一个ObservableCollection,再给itemcontrol吗
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2015-10-13 17:54:00
5#
回复 4楼feiyan0320的帖子

直接给一个tile绑定ObservableCollection数据源。
如果是由于嵌套在其他控件内部,无法绑定,那么就先根据控件找到内部控件tile,然后设置绑定。
wpf本身支持根据控件名查找控件,你可以在网上搜到相关的资料。
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
feiyan0320
中级会员   /  发表于:2015-10-13 18:03:00
6#
回复 5楼Alice的帖子

如果我要嵌套到itemcontrol里,想呈现无数个tile,那我只能通过控件查找到每一个tile然后分别把每个集合绑定吗
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2015-10-14 10:04:00
7#
回复 6楼feiyan0320的帖子

根据我的理解,ObservableCollection集合中有多个对象的示例。C1Tile通过ContentSource绑定到这个集合后,就会按照多个对象的实例自动展示出多个磁贴去显示全部,实际的C1Tile的内容就是多个。

还是说我对你的业务场景的理解有偏差?
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
feiyan0320
中级会员   /  发表于:2015-10-14 22:47:00
8#
回复 7楼Alice的帖子

我把ObservableCollection集合给了tile的ContentSource,似乎只有一个tile,而且如果集合是一个字符串的话,磁贴上展示的是一个一个字符的滚动。
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2015-10-15 09:12:00
9#
回复 8楼feiyan0320的帖子

把你修改后的demo发给我们,我们帮你看看。
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
feiyan0320
中级会员   /  发表于:2015-10-15 16:41:00
10#
回复 9楼Alice的帖子
  1. <ItemsControl  x:Name="itemsControl" ItemsSource="{Binding CVList}" Grid.ColumnSpan="3" Margin="0,4,0,0" Grid.Row="1">
  2.                     <ItemsControl.Template>
  3.                         <ControlTemplate>
  4.                             <ScrollViewer x:Name="ScrollViewer" Padding="{TemplateBinding Padding}">
  5.                                 <ItemsPresenter />
  6.                             </ScrollViewer>
  7.                         </ControlTemplate>
  8.                     </ItemsControl.Template>
  9.                     <ItemsControl.ItemsPanel>
  10.                         <ItemsPanelTemplate>
  11.                             <WrapPanel Orientation="Horizontal"/>
  12.                         </ItemsPanelTemplate>
  13.                     </ItemsControl.ItemsPanel>
  14.                     <ItemsControl.ItemTemplate>
  15.                         <DataTemplate>
  16.                             <Border Padding="3">
  17.                                 <WrapPanel>
  18.                                     <c1:C1SlideTile Content="C1SlideTile" HorizontalAlignment="Left" Margin="0,0,0,0" ContentSource="{Binding Member}"
  19.                         VerticalAlignment="Top" c1:C1TileService.PointerDownAnimation="True" Width="277" Height="100" Padding="0">
  20.                                         <c1:C1Tile.ContentTemplate>
  21.                                             <DataTemplate>
  22.                                                 <Grid  Width="277" Height="100">
  23.                                                     <Grid.Resources>
  24.                                                         <Style
  25.                 TargetType="Border">
  26.                                                             <Setter
  27.                     Property="BorderBrush"
  28.                     Value="LightGray"></Setter>
  29.                                                             <Setter
  30.                     Property="BorderThickness"
  31.                     Value="1"></Setter>
  32.                                                         </Style>
  33.                                                     </Grid.Resources>
  34.                                                     <Grid.RowDefinitions>
  35.                                                         <RowDefinition Height="27*"/>
  36.                                                         <RowDefinition Height="23*"/>
  37.                                                         <RowDefinition Height="28*"/>
  38.                                                         <RowDefinition Height="22*"/>
  39.                                                     </Grid.RowDefinitions>
  40.                                                     <Grid.ColumnDefinitions>
  41.                                                         <ColumnDefinition Width="26*"/>
  42.                                                         <ColumnDefinition Width="45*"/>
  43.                                                         <ColumnDefinition Width="23*"/>
  44.                                                         <ColumnDefinition Width="8*"/>
  45.                                                         <ColumnDefinition Width="88*"/>
  46.                                                         <ColumnDefinition Width="87*"/>
  47.                                                     </Grid.ColumnDefinitions>
  48.                                                     <Grid.Background>
  49.                                                         <LinearGradientBrush EndPoint="1,0" StartPoint="0.0,0.0">
  50.                                                             <GradientStop Color="White"/>
  51.                                                             <GradientStop Color="Thistle"  Offset="1"/>
  52.                                                         </LinearGradientBrush>
  53.                                                     </Grid.Background>
  54.                                                     <Border  Grid.ColumnSpan="6" Grid.RowSpan="4"/>
  55.                                                     <Label x:Name="bh" Foreground="DimGray"  FontSize="13" FontFamily="微软雅黑" FontWeight="Bold" Height="26" VerticalAlignment="Center" VerticalContentAlignment="Center"
  56.                Margin="8,1,3,0" HorizontalContentAlignment="Center" Opacity="0.5" Grid.Column="2"
  57.                Content="{Binding OrderNo}" Grid.ColumnSpan="3"/>
  58. </Grid>
  59.                                             </DataTemplate>
  60.                                         </c1:C1Tile.ContentTemplate>
  61.                                         <!--<c1:C1Tile.BackContentTemplate>
  62.                                             <DataTemplate></DataTemplate>
  63.                                         </c1:C1Tile.BackContentTemplate>-->
  64.                                     </c1:C1SlideTile>
  65.                                 </WrapPanel>
  66.                             </Border>
  67.                         </DataTemplate>
  68.                     </ItemsControl.ItemTemplate>
  69.                 </ItemsControl>
复制代码


这里的CVList就是一个ObservableCollection<Member>集合,tile的contentsource绑定的是Member,然后里面有个label绑定的是Member的属性OrderNo
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部