Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Bind ToggleButton To TreeViewItem
Message
General information
Forum:
ASP.NET
Category:
Windows Presentation Foundation (WPF)
Miscellaneous
Thread ID:
01464577
Message ID:
01464657
Views:
26
>>>I want to bind the IsChecked property of ToggleButton to the IsSelected property of the TreeViewItem, but I don't know how. When the
>>>ToggleButton is set, I want to selectd the TreeViewItem.
>>
>>Which TreeViewItem - bearing in mind that the WPF Treeview doesn't (out of the box) support multi-select?
>
>The SelectedItem

I think this gives you what you are asking for:
<Window x:Class="WpfApplication1.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <StackPanel>
        <TreeView x:Name="TV">
            <TreeViewItem Header="One" IsSelected="True"></TreeViewItem>
            <TreeViewItem Header="Two"></TreeViewItem>
        </TreeView>
        <ToggleButton IsChecked=
              "{Binding ElementName=TV,Path=SelectedItem.IsSelected,Mode=TwoWay}" />
    </StackPanel>
</Window>
- but I doubt if it can give you what you need because the act of unchecking the button will change the 'IsSelected' status of the TreeViewItem at which point it is no longer the selected item so, by extension, there is nothing for the Toggle button to bind to......
Previous
Reply
Map
View

Click here to load this message in the networking platform