0

HierarchicalDataTemplate で定義されてTreeViewいる<ItemTemplate>

 <HierarchicalDataTemplate ItemsSource="{Binding}"
                              x:Key="TreeTemplate">
    <StackPanel Orientation="Horizontal">
        <TextBlock Name="TextBlockProperty" Text="{Binding Name}" Width="110" Foreground="#FF3C3C3C" >
            <TextBlock.Style>
                <Style TargetType="TextBlock">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding ModifyType}" Value="AutoDetect">
                            <Setter Property="Background">
                                <Setter.Value>
                                    <SolidColorBrush Color="LightGreen"></SolidColorBrush>
                                </Setter.Value>
                            </Setter>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding ModifyType}" Value="Prerequisite">
                            <Setter Property="Background">
                                <Setter.Value>
                                    <SolidColorBrush Color="LightSkyBlue"></SolidColorBrush>
                                </Setter.Value>
                            </Setter>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding ModifyType}" Value="AutoCheckFailed">
                            <Setter Property="Background">
                                <Setter.Value>
                                    <SolidColorBrush Color="Red"></SolidColorBrush>
                                </Setter.Value>
                            </Setter>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </TextBlock.Style>
        </TextBlock>
        <ContentControl Name="ContentCtrl" Content="{Binding}">
        </ContentControl>
    </StackPanel>
    <HierarchicalDataTemplate.Triggers>
        <DataTrigger Binding="{Binding ControlType}" Value="Text">
            <Setter TargetName="ContentCtrl" Property="ContentTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <TextBox Width="130" Text="{Binding Value}" BorderThickness="0" Background="#FFF8F8F8"></TextBox>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </DataTrigger>
        <DataTrigger Binding="{Binding ControlType}" Value="Choice">
            <Setter TargetName="ContentCtrl" Property="ContentTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <ComboBox Width="130" IsEditable="True" ItemsSource="{Binding ChoiceItems}" Text="{Binding Value}" BorderThickness="0" >
                        </ComboBox>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </DataTrigger>
        <DataTrigger Binding="{Binding ControlType}" Value="Group">
            <Setter TargetName="ContentCtrl" Property="ContentTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <TextBlock></TextBlock>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </DataTrigger>
    </HierarchicalDataTemplate.Triggers>
</HierarchicalDataTemplate>

また、を使用して の TextBlockPropertyの幅を短く/広くするために、の外側に2 つの<Buttons> ShowDefaultHideDefaultを定義しました。しかし、私はそれを行う方法がわかりません。<Page.Resources> <TextBlock><HierarchicalDataTemplate>Storyboard

であるためTreeView、アイテムは実際にはフォームに似た複数の列と行であり、 にバインドされてい<HierarchicalDataTemplate>ます。しかし、2つのボタンはGrid外側で定義されてい<Page.Resources>ます...幅の短縮/拡大を行うために、で使用Storyboard<Page.Resources>ます。

<Storyboard x:Key="ShowDefault">
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Width" Storyboard.TargetName="GroupList">
            <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0"/>
        </DoubleAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Width" Storyboard.TargetName="PropertyTree">
            <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="270"/>
        </DoubleAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Width" Storyboard.TargetName="DefaultTree">
            <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="182"/>
        </DoubleAnimationUsingKeyFrames>

    </Storyboard>
    <Storyboard x:Key="HideDefault">
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Width" Storyboard.TargetName="GroupList">
            <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="152"/>
        </DoubleAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Width" Storyboard.TargetName="PropertyTree">
            <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="299"/>
        </DoubleAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Width" Storyboard.TargetName="DefaultTree">
            <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0"/>
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>

そして、次のStoryboardように呼び出します。

<Page.Triggers>
    <EventTrigger RoutedEvent="ButtonBase.Click" SourceName="ShowDefaultValue">
        <BeginStoryboard Storyboard="{StaticResource ShowDefault}"/>
    </EventTrigger>
    <EventTrigger RoutedEvent="ButtonBase.Click" SourceName="HideDefaultValue">
        <BeginStoryboard Storyboard="{StaticResource HideDefault}"/>
    </EventTrigger>
</Page.Triggers>

少し複雑ですが、正しく理解していただければ幸いです。

ヘルプや提案をいただければ幸いです。:)

4

2 に答える 2

0

OK、最終的には 2 つの の<ScrollView>外側にa を追加して問題を解決します。DataBinding などを変更する必要はありません。<StackPanel><TreeView>

于 2013-11-11T03:44:08.800 に答える
0

あなたが何を達成しようとしているのかわからないので、あなたが何を意味しているのか推測する必要があります:)。

TextBlock への参照を取得するには、次のように Loaded イベントにアタッチできます。

<TextBlock Loaded="TextBoxLoaded"></TextBlock>
 private TextBlock _textBlock;
        private void TextBoxLoaded(object sender, RoutedEventArgs e)
        {
            _textBlock = sender as TextBlock;
        }

ボタンをクリックすると、TextBlock のプロパティが変更されます。

通常、ボタンは、子テンプレートの各アイテムのテンプレートにもある必要があります。

于 2013-11-08T06:42:19.377 に答える