【发布时间】:2011-02-13 17:30:53
【问题描述】:
我对一些复杂的数据绑定有疑问。
我希望能够更新一个网格(其属性“IsItemsHost”设置为 true)
每当发生数据绑定时动态地进行。
实际上我使用的是一个 CustomControl,它是一个 ItemsControl 和这个
在其 ControlTemplate 中有 Grid。
更具体地说,我将网格绑定到一些项目,我想 根据这些项目更改网格行数, 添加类似标题的内容(一行包含一些文本), 并使用一些自定义逻辑设置项目的 Grid.Row 和 Grid.Column。
应用此类行为的最简单方法是什么 绑定数据何时更新?
我必须使用还包含标题数据的视图模型吗?
提前致谢。
CustomControl Generic.xaml 的代码:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:TimeTableControl">
<Style TargetType="{x:Type local:TimeTableControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:TimeTableControl}">
<Border Width="Auto" Height="Auto" BorderBrush="#FF4B5A9B" BorderThickness="4" CornerRadius="4" Margin="2" Padding="0" Background="White">
<Grid Width="Auto">
<Grid.RowDefinitions>
<RowDefinition Height="0.1*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Viewbox>
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=DayCaption}"/>
</Viewbox>
<Border Grid.Row="1" BorderThickness="0,2,0,0" BorderBrush="#FF4B5A9B">
<Grid Name="ContentGrid" IsItemsHost="True">
</Grid>
</Border>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
【问题讨论】:
标签: wpf data-binding viewmodel