我想将WPF数据网格中的文本块文本绑定到依赖项属性。不知何故,没有显示,但当我在网格外使用相同的文本块绑定时,一切正常。下面是我的代码,依赖属性WPF Grid
</Grid.RowDefinitions>
<StackPanel Grid.Row="0">
<toolkit:DataGrid Name="definitionGrid" Margin="0,10,0,0" AutoGenerateColumns="False"
CanUserAddRows="False" CanUserDeleteRows="False" IsReadOnly="False"
RowHeight="25" FontWeight="Normal" ItemsSource="{Binding Subscription}"
ColumnHeaderStyle="{DynamicResource ColumnHeaderStyle}"
SelectionMode="Single" ScrollViewer.HorizontalScrollBarVisibility="Disabled" Width="450"
ScrollViewer.VerticalScrollBarVisibility="Auto" Height="200">
<toolkit:DataGridCheckBoxColumn Header="Email" Width="60" Binding="{Binding ReceivesEmail}" CellStyle="{StaticResource cellCenterAlign}"/>
<toolkit:DataGridTemplateColumn Header="Others" Width="220" CellStyle="{StaticResource cellCenterAlign}" IsReadOnly="True">
<toolkit:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=OtherSubs}"/>
</DataTemplate>
</toolkit:DataGridTemplateColumn.CellTemplate>
</toolkit:DataGridTemplateColumn>
</toolkit:DataGrid.Columns>
</toolkit:DataGrid>
<TextBlock Text="{Binding Path=OtherSubs}"/>
</StackPanel>
代码隐藏
public string OtherSubs
{
get { return (string)GetValue(OtherSubsProperty); }
set { SetValue(OtherSubsProperty, value); }
}
public static readonly DependencyProperty OtherSubsProperty = DependencyProperty.Register("OtherSubs", typeof(string),
typeof(ProgramSubscriptions), new UIPropertyMetadata(string.Empty));
//other....
for (int i = 0; i < OtherPrgList.Count; i++)
{
foreach (int y in myList)
{
ProgramSubscriptionViewModel otheritem = OtherPrgList[i];
if (y == otheritem.Program.ID)
OtherSubs += otheritem.Subscriber.Username + ", ";
}
}
请不要让我知道如果有另一种方式,我可以完成这项工作,而不是使用一个DependencyProperty,althouht测试我做把数据网格下面的文本块,它工作得很好.. 帮助!
我假设OtherSubs是一个集合中的类的一部分,并且DataGrid的ItemsSource被设置为这个集合? – 2010-04-22 15:57:58