0

我有一个在 HierarchicalDataTemplateTreeView<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>

<Buttons> 还在. _ _ _ <Page.Resources>_ _ _ _ <TextBlock> _ <HierarchicalDataTemplate>_ Storyboard但我不知道该怎么做。

因为是a TreeView,所以Items其实是几列多行,更像是一个表单,绑定在<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

我不确定您要达到什么目的,所以我必须猜出您的意思:)。

要获得对 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 回答
0

好的,我最终通过在两个s<ScrollView>之外添加一个来解决问题。无需更改 DataBinding 或其他任何内容。<StackPanel><TreeView>

于 2013-11-11T03:44:08.800 回答