0

WPFデータグリッドのテキストブロックテキストを依存関係プロパティにバインドしたいと思います。どういうわけか、何も表示されませんが、グリッドの外側で同じテキストブロックバインディングを使用すると、すべてが正常に機能します。以下は私のコードです、

        </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 + ", ";
            }
        }

依存関係プロパティを使用する代わりに、この機能を実現する別の方法があるかどうかを教えてください。テストには、データグリッドの下にテキストブロックを配置しましたが、完全に機能します。ヘルプ!

4

2 に答える 2

2

Subscriptionプロパティは、 ProgramSubscriptionsオブジェクトのコレクションである必要があります。少なくともIEnumerableインターフェイスをサポートする必要があります。通常、 List<ProgramSubscriptions>のようなものがあります。さらに、OtherSubsは明らかにProgramSubscriptionsのプロパティであり、これは問題ありません。

「グリッド外の同じテキストブロックバインディング」の使用方法を教えてください。

于 2010-04-22T16:55:27.573 に答える
0

DataGrid をサブスクリプションにバインドしています。これは、DataGrid の DataContext が何であれ、プロパティである必要があります。wpfwannabe が言ったように、IEnumerable をサポートする必要があります。理想的には、ObservableCollection<>または派生があるため、DataGrid は自動的に更新されます。

そこから、DataGrid は表示する項目を取得します。実際のデータを表示するには、DataGridTemplateColumn 定義が必要です。OtherSubs にバインドするため、これは、Subscription IEnumerable によって列挙されるオブジェクトがそのプロパティを持つ必要があることを意味します。ところで、これが機能するために依存関係プロパティである必要はありません。

于 2010-04-22T17:07:26.907 に答える