我想將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