Click here to Skip to main content
15,880,967 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i am new in wpf and i trying things in "Bind"

what i try it and work

What I have tried:

<ComboBox x:Name="cmbBxService" Width="265">

  <ComboBoxItem Content="<big>Item01</big>" Tag="/Images/Services/Image01.png" />

  <ComboBoxItem Content="Item02" Tag="/Images/Services/Image02.png" />

  <ComboBoxItem Content="Item03" Tag="/Images/Services/Image03.png" />

</ComboBox>

<StackPanel x:Name="Option">

  <TextBlock Text="Name" />

  <TextBox x:Name="OptionName" Width="230" />

  <StackPanel.Style>
    <Style TargetType="{x:Type StackPanel}">

      <Setter Property="Visibility" Value="Collapsed" />

        <Style.Triggers>

          <DataTrigger Binding="{Binding ElementName=cmbBxService, Path=SelectedItem.Content}" Value="Item01">

            <Setter Property="Visibility" Value="Visible" />

          </DataTrigger>

        </Style.Triggers>

    </Style>

  </StackPanel.Style>

</StackPanel>



and i am using
GitHub - ghost1372/HandyControls: Contains some simple and commonly used WPF controls based on HandyControl[^]

and add SideMenu from HandyControls even if i use Treeview

what i need is to collapse StackPanels by user chooses in "SideMenu" or "Treeview"


in next example of code not work but it is the same Way of Binding

<hc:SideMenu
    x:Name="MySideMenu"
    Grid.Column="0"
    Width="200"
    Margin="5"
    BorderThickness="1"
    SelectionChanged="MySideMenu_SelectionChanged">

    <hc:Interaction.Triggers>
        <hc:EventTrigger EventName="SelectionChanged">
            <hc:EventToCommand Command="{Binding SwitchItemCmd}" PassEventArgsToCommand="True" />
        </hc:EventTrigger>
    </hc:Interaction.Triggers>

    <hc:SideMenuItem Header="Overview" IsSelected="True">

        <hc:SideMenuItem.Icon>
            <Image
                Width="24"
                Height="24"
                Source="/Folder/01.png" />
        </hc:SideMenuItem.Icon>

        <hc:SideMenuItem
            x:Name="MySummary"
            Header="Summary"
            IsSelected="False">
            <hc:SideMenuItem.Icon>
                <TextBlock Text="" />
            </hc:SideMenuItem.Icon>
        </hc:SideMenuItem>

        <hc:SideMenuItem Header="Dashboards">
            <hc:SideMenuItem.Icon>
                <TextBlock Text="" />
            </hc:SideMenuItem.Icon>
        </hc:SideMenuItem>

        <hc:SideMenuItem Header="Wiki">
            <hc:SideMenuItem.Icon>
                <TextBlock Text="" />
            </hc:SideMenuItem.Icon>
        </hc:SideMenuItem>
    </hc:SideMenuItem>

</hc:SideMenu>



    <StackPanel
        Width="200"
        Height="200"
        Background="Red">
        <StackPanel.Style>
            <Style TargetType="{x:Type StackPanel}">

                <Style.Triggers>

                    <DataTrigger Binding="{Binding ElementName=MySideMenu, Path=Header}" Value="Summary">

                        <Setter Property="Visibility" Value="Collapsed" />

                    </DataTrigger>

                </Style.Triggers>

            </Style>
        </StackPanel.Style>

    </StackPanel>


i want to Collaps StackPanel or show it only by using XAML Not Any C# Code and NO MVVM


why the code work in FIRST example and the second example NOT working and how can i fix my XAML code?

thanks
Posted
Updated 31-Jan-23 19:56pm
Comments
[no name] 31-Jan-23 13:36pm    
If you're "new" to WPF, don't confuse yourself with third party tools; there is enough native functionality to keep you busy and in less trouble.
Graeme_Grant 31-Jan-23 14:40pm    
You need to contact the owner of that library.
Eng Mohamed Bassuny 31-Jan-23 15:49pm    
this not work in treeview even not only HandyControls
Graeme_Grant 31-Jan-23 16:28pm    
The code posted above has nothing to do with the TreeView control. Here is a primer on the TreeView control: A simple TreeView example - The complete WPF tutorial[^]
[no name] 1-Feb-23 0:13am    
The second example "doesn't work" because "SideMenu" is NOT inside the stack panel you're collapsing; and since a StackPanel is not visible unless it has a background color, you only think it's not working.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900