已答覆 Set Focus / Selection to child item

  • 29 สิงหาคม 2549 9:59
     
     

    Hi All,

    I have a TreeView control with several TreeViewItem objects. My TreeViewItem object consists of a DockPanel and my DockPanel consists of an Image object and a TextBlock object. Now what I basically want to do, is on the selection of the TreeViewItem, bubble the selection down to the TextBlock. So that my Image is not in a "selection" mode.

    The reason for this is once I select my TreeViewItem, it selects my entire TreeViewItem giving my Image an ugly blue background colour which I would like to avoid if possible...

    Alternatively, if someone could help me "override" the default selection style so I can set it transparent and force my TextBlock item to then have the "selection" background...

    Kind Regards

ตอบทั้งหมด

  • 29 สิงหาคม 2549 11:27
    ผู้ดูแล
     
     คำตอบ

    try this

    <TreeView.Resources>

    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}">Transparent</SolidColorBrush>

    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}">Black</SolidColorBrush>

    </TreeView.Resources>

  • 29 สิงหาคม 2549 11:35
     
     

    Hi lee d,

    How would I go about converting this to C#?

    Sorry, but I'm building my treeview in code and all my resources etc. are located in my code.

    Thanx for your effort!

    Regards

  • 29 สิงหาคม 2549 12:26
    ผู้ดูแล
     
     

    Add the following to XAML file

    <Style x:Key="noHighlight" TargetType="{x:Type TreeViewItem}">

    <Style.Resources>

    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}">Transparent</SolidColorBrush>

    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}">Black</SolidColorBrush>

     

    </Style.Resources>

    </Style>

    and in the codebehind,  set the ItemContainerStyle

    TreeView tv1;

    tv1.ItemContainerStyle = this.FindResource("noHighlight") as Style;