2

I have a treeview with checkboxes for each item using a DataTemplate and 2 HierarchicalDataTemplates (My binded list consists of 2 or 3 levels, and the checkboxes only appear on the leaf level - the last one).

The leaf looks like so:

<TreeView ItemsSource="{Binding}">
<DataTemplate DataType="{x:Type local:MatchDataLeaf}">
    <Grid Margin="3">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="240"/>
            <ColumnDefinition Width="100"/>
            <ColumnDefinition Width="150"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="60"/>
        </Grid.ColumnDefinitions>

        <StackPanel Grid.Column="0" Orientation="Horizontal">
            <CheckBox x:Name="selectCheckBtn" Grid.Column="0" IsChecked="True" Click="select_Click"
                      Tag="{Binding}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TreeViewItem}}}"/>
            <TextBlock Grid.Column="1" Margin="5,0,0,0" Text="{Binding Path=Name}" FontFamily="Arial" FontSize="12" FontWeight="Bold" Foreground="Black" VerticalAlignment="Center"/>
        </StackPanel>
    </Grid>
</DataTemplate>

My problem occurs when I click on one of the leaf items' TextBlock part - if I click the checkbox everything is OK. When I click the item, the whole tree moves left, hiding the + expand button, and I don't have a way of getting it back. It sort of aligns the checkbox to the left of the container, thus hiding all what's above and left of it.

I realize this is weird UI issue, and I doubt anyone has seen this before. So let me ask this: Is there a way to somehow disalow that click? Can I tell WPF to do NOTHING if I click that part of the item? I tried setting the Handled to true on the MouseLeftButtonUp handler of the Textblock, but that doesn't do anything useful for me.

Any other suggestions are welcome - I have no idea how to approach this thing.

1 Answer 1

0

try putting the whole TreeView into a ScrollViewer to me it sounds the content is to big to fit the available area:

<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
        <TreeView ..../>
</ScrollViewer>
3
  • Adding the scrollviewer didn't help me - But you are right - I just made all of the Width/Height to Auto and expanded the whole window, and its all there - Thanks.
    – user350213
    Dec 6, 2010 at 18:09
  • Btw, is there way to change the Selected state of an item to be NOTHING? I know I can use Trigger to change the style of the selected state, but how do I have it not select at all?
    – user350213
    Dec 6, 2010 at 18:12
  • thanks for marking the answer! I'm not sure what you mean with "Selected state of an item to be NOTHING", it would be better anyway to post another question, as it is a different topic. Dec 6, 2010 at 18:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.