0

やあ。が にあるという問題が発生していRadExpanderますRadListBox基本的に、私はhereまたはhereのようなものを持っています。

バインドがありますが、折りたたまれたときではなく、展開されOneWayToSourceたときにのみバインドが発生するようにします。RadExpander

2 つの UI 要素を条件付きでバインドする方法はありますか?

EDIT : (一部のダウン投票者を幸せにするサンプルコード)

<DataTemplate x:Key="ListBoxItemTemplate" DataType="{x:Type telerik:RadListBoxItem}">
    <!--<DataTemplate.Triggers>
        <DataTrigger Binding="{Binding ElementName=listExpander, Path=IsExpanded, Mode=TwoWay}" Value="True">
            <Setter Property="IsSelected" Value="True" />
        </DataTrigger>
    </DataTemplate.Triggers>-->
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <telerik:RadExpander x:Name="listExpander"
                             IsExpanded="{Binding Mode=TwoWay, IsAsync=True, Path=IsSelected, RelativeSource={RelativeSource AncestorType=telerik:RadListBoxItem, Mode=FindAncestor}}"
                             VerticalContentAlignment="Top" ToolTip="Double click on the List name to edit it">
            <telerik:RadExpander.Header>
                <Grid>
                    <TextBlock x:Name="listNameCaption" MouseDown="listName_txtblk_MouseDown"
                               Text="{Binding ListName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource HighlightedDetailsStyleForTextBlock}" />
                    <TextBox LostFocus="listName_txtbox_LostFocus" Visibility="Collapsed"
                             Text="{Binding ListName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                             Style="{StaticResource HighlightedDetailsStyleForTextBox}" />
                </Grid>
            </telerik:RadExpander.Header>
            <telerik:RadExpander.Content>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Border BorderBrush="#FFDADADA" BorderThickness="0,0,1,1" MinHeight="20" MinWidth="200" CornerRadius="3" Margin="5">
                        <Border BorderBrush="#B2ADBDD1" BorderThickness="1" CornerRadius="2">
                            <StackPanel>
                                <StackPanel Orientation="Horizontal">
                                    <Label FontFamily="Segoe UI" FontSize="11" Content="List Type:" FontStyle="Italic" />
                                    <Label FontFamily="Segoe UI" FontSize="11" Content="{Binding ListType}" />
                                </StackPanel>
                                <StackPanel Orientation="Horizontal">
                                    <Label FontFamily="Segoe UI" FontSize="11" Content="Tree:" FontStyle="Italic" />
                                    <Label FontFamily="Segoe UI" FontSize="11" Content="{Binding TreeName}" />
                                </StackPanel>
                                <StackPanel Orientation="Horizontal">
                                    <Label FontFamily="Segoe UI" FontSize="11" Content="Discount Date:" FontStyle="Italic" />
                                    <Label FontFamily="Segoe UI" FontSize="11" Content="{Binding DiscountDate}" />
                                </StackPanel>
                            </StackPanel>
                        </Border>
                    </Border>
                </Grid>
            </telerik:RadExpander.Content>
            <!--<telerik:RadExpander.Style>
                <Style TargetType="{x:Type telerik:RadExpander}">
                    <Style.Triggers>
                        <Trigger Property="IsExpanded" Value="True">
                            <Setter Property="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem, Mode=FindAncestor}, Path=IsSelected}" Value="True"/>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </telerik:RadExpander.Style>-->
        </telerik:RadExpander>
    </Grid>
</DataTemplate>

<telerik:RadListBox x:Name="allListBox"
                    Style="{StaticResource ListBoxStyle}"
                    ItemsSource="{Binding Lists, Mode=TwoWay}"
                    ItemTemplate="{StaticResource ListBoxItemTemplate}"
                    SelectedItem="{Binding SelectedListItem, Mode=TwoWay}">
    <telerik:RadListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <VirtualizingStackPanel Orientation="Vertical" />
        </ItemsPanelTemplate>
    </telerik:RadListBox.ItemsPanel>
</telerik:RadListBox>

編集2

修正しましたが、コードビハインドからです。XAML から「RadExpander - RadListBoxItem の IsSelected プロパティにバインドするのは、IsExpanded=True の場合のみ」という単純な方法があればいいのにと思います。

これは回避策のコードです:

private void ListItemExpanded(object sender, RadRoutedEventArgs e)
{
    var listItem = sender as RadExpander;
    if(listItem == null)
        return;

    if (!listItem.IsExpanded) return;


    var parent = VisualTreeHelper.GetParent(listItem);
    while (parent != null && !(parent is RadListBoxItem))
    {
        parent = VisualTreeHelper.GetParent(parent);
    } 

    if(parent == null)
        return;

    var listBoxItem = parent as RadListBoxItem;
    if (!listBoxItem.IsSelected)
        listBoxItem.IsSelected = true;
}

<telerik:RadExpander x:Name="listExpander" Expanded="ListItemExpanded" VerticalContentAlignment="Top" ToolTip="Double click on the List name to edit it">
4

1 に答える 1

1

解決策 1. 展開イベントに反応し、コードを使用して要素のバインディングを変更します。

解決策 2: MultiBinding と IMultiValueConverter を使用する: http://www.switchonthecode.com/tutorials/wpf-tutorial-using-multibindings

于 2012-11-01T17:29:25.627 に答える