私はこのようなListBox
ました:私はTextBlockののリストでDataTemplate
をしました、その中バインドされた値がnullの場合は項目を非表示にしますか?
<ListBox VerticalAlignment="Stretch"
ItemsSource="{Binding EventInfo}">
を:私は何をする必要があるか
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="20"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Text="Event:" FontWeight="Bold" Grid.Column="0" Grid.Row="0"/>
<TextBlock Text="{Binding Name}" FontWeight="Bold" Grid.Column="1" Grid.Row="0"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
は、例えばときのTextBlockを隠しています、バインドされた値はnull
です。
Event: foo
しかしName
がnullのいくつかの場合には、私は両方TextBlock
Event
とバインドさを非表示にする必要があり、これを行うことも可能である:私はこのようなものが準きましたか?
UPDATE:
私はXAMLでこの純粋をやろうとしているよう:
:問題は、アプリケーションの中断モードでの秋ととしてXAMLエラーは私が得ることだ<Style TargetType="TextBlock">
<Style.Triggers>
<Trigger Property="Text" Value="">
<Setter Property="Visibility" Value="Collapsed" />
</Trigger>
<Trigger Property="Text" Value="{x:Null}">
<Setter Property="Visibility" Value="Collapsed" />
</Trigger>
</Style.Triggers>
</Style>
System.Windows.Data Error: 40 : BindingExpression path error: 'Name' property not found on 'object' ''Style' (HashCode=7)'.
このエラーは、私が間違っているテキストブロックごとに繰り返されますか?
これは純粋なxamlでのみ可能ですか? – AgainMe
はい、純粋なxamlでデータトリガーを定義することはできますが、私は個人的にセッターメソッドをより明確でより強力なものにしています...私の回答を編集してxamlトリガーの例も挿入します –
私の更新をご覧ください。私はxamlでこれを純粋にすることを試みていますが、それは私のコードでは間違っていると思います。 – AgainMe