Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Folks:

I am some xaml file for user interface in my C# C++ project. I have toolbar which is pre-defined as follows:
XML
<UserControl x:Class="ImageReviewDll.View.ToolBarView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ViewModel="clr-namespace:ImageReviewDll.ViewModel"
    Height="Auto" Width="Auto">
    <UserControl.Resources>
        <ResourceDictionary>
            <DataTemplate DataType="{x:Type ViewModel:ImageReviewViewModel}"></DataTemplate>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="..\Button.xaml" />
                <ResourceDictionary Source="..\tooltip.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid>
        <Border BorderThickness="1,1,1,1"
                BorderBrush="White"
                CornerRadius="12,12,12,12"
                Margin="1">
            <ListView Name="lvViewerControl"
                  SelectionMode="Single"
                  SelectedIndex="{Binding Path=ViewType, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                  removed="{x:Null}"
                  BorderBrush="{x:Null}"
                  Margin="2">
                <Label Name="lblView2D" 
                       Width="40" 
                       Height="40" 
                       Margin="3"             
                       Background="#FF595959"
                       Foreground="White"
                       HorizontalContentAlignment="Center"
                       VerticalContentAlignment="Center" >
                    <Image Source="/ImageReview;component/Icons/2D.png" />
                </Label>
                <Label Name="lblView3D" 
                       Width="40" 
                       Height="40" 
                       Margin="3"
                       Background="#FF595959"
                       Foreground="White"
                       HorizontalContentAlignment="Center"
                       VerticalContentAlignment="Center">
                    <Image Source="/ImageReview;component/Icons/3D.png" />
                </Label>
                <Label Name="lblViewTiles"
                       Width="40"
                       Height="40"
                       Margin="3"
                       Background="#FF595959"
                       Foreground="White"
                       HorizontalContentAlignment="Center"
                       VerticalContentAlignment="Center">
                    <Image Source="/ImageReview;component/Icons/Tile.png" />
                </Label>
            </ListView>
        </Border>
    </Grid>
</UserControl>


This basically defines 3 buttons as "lblView2D", "lblView3D", "lblViewTiles";

So, in the same user interface, there is another button, which when it is clicked, this pre-defined toolbar will show up, like following:
XML
<Border Grid.Column="2" >
                        <StackPanel>
                            <View:ToolBarView x:Name="toolBarView"/>
                        </StackPanel>
                    </Border>

But what I want is, this toolbar shows up WITHOUT "lblViewTiles" button displayed. Is there any way I can do this? I think I should do some change in the caller code;
Thanks a lot.
Here is the entire code of the button that loads the pre-defeined:
XML
<UserControl x:Class="ImageReviewDll.MainWindow"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:View="clr-namespace:ImageReviewDll.View"
             xmlns:ViewModel="clr-namespace:ImageReviewDll.ViewModel"
             xmlns:local="clr-namespace:ImageReviewDll"
             xmlns:Spin="clr-namespace:SpinnerProgress;assembly=SpinnerProgress"
             Name="mwUserControl">
    <UserControl.Resources>
        <ResourceDictionary>
            <Style x:Key="CloseButtonStyle"
                   TargetType="{x:Type Button}">
                <Setter Property="Background">
                    <Setter.Value>
                        <LinearGradientBrush EndPoint="0.5, 1"
                                             StartPoint="0.5, 0">
                            <GradientStop Color="White"
                                          Offset="0.0" />
                            <GradientStop Color="Red"
                                          Offset="0.35" />
                        </LinearGradientBrush>
                    </Setter.Value>
                </Setter>
                <Setter Property="Foreground"
                        Value="White" />
                <Setter Property="FontWeight"
                        Value="Bold" />
                <Setter Property="VerticalAlignment"
                        Value="Top"></Setter>
                <Setter Property="Content"
                        Value="X"></Setter>
                <Setter Property="BorderBrush"
                        Value="White"></Setter>
                <Setter Property="BorderThickness"
                        Value="1"></Setter>
            </Style>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source=".\Button.xaml" />
                <ResourceDictionary Source=".\tooltip.xaml" />
                <ResourceDictionary Source=".\Label.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid>
        <Grid.Resources>
            <ResourceDictionary>
                <local:ViewTypeToVisibilityConverter x:Key="ViewTypeConverter" />
                <BooleanToVisibilityConverter x:Key="boolToVis" />
                <ResourceDictionary.MergedDictionaries></ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
        </Grid.Resources>
        <StackPanel>
            <StackPanel Orientation="Horizontal"
                        HorizontalAlignment="Center">
                <StackPanel.Resources>
                    <Style TargetType="{x:Type RadioButton}">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type RadioButton}">
                                    <BulletDecorator removed="Transparent">
                                        <BulletDecorator.Bullet>
                                            <Grid Width="125"
                                                  Height="50">
                                                <Rectangle x:Name="CheckMark"
                                                           Fill="Gray"
                                                           RadiusX="5"
                                                           RadiusY="5"
                                                           Margin="0.5,0.5,0.5,0.5" />
                                                <ContentPresenter />
                                            </Grid>
                                        </BulletDecorator.Bullet>
                                    </BulletDecorator>
                                    <ControlTemplate.Triggers>
                                        <Trigger Property="IsChecked"
                                                 Value="true">
                                            <Setter TargetName="CheckMark"
                                                    Property="Fill"
                                                    Value="DarkGray" />
                                        </Trigger>
                                    </ControlTemplate.Triggers>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </StackPanel.Resources>
                <RadioButton Name="rbExpReview"
                             Foreground="White">
                    <RadioButton.Content>
                        <Label Content="Experiment Review"
                               HorizontalContentAlignment="Center"
                               VerticalContentAlignment="Center" />
                    </RadioButton.Content>
                </RadioButton>
                <RadioButton Name="rbExpReviewDZ"
                             Foreground="White">
                    <RadioButton.Content>
                        <Label Content="Exp Rev. Deep Zoom"
                               HorizontalContentAlignment="Center"
                               VerticalContentAlignment="Center" />
                    </RadioButton.Content>
                </RadioButton>
                <RadioButton Name="rbSIReview"
                             Foreground="White">
                    <RadioButton.Content>
                        <Label Content="Single Image Review"
                               HorizontalContentAlignment="Center"
                               VerticalContentAlignment="Center" />
                    </RadioButton.Content>
                </RadioButton>
            </StackPanel>
            <Grid>
                <Grid Name="expGrid"
                      Margin="5"
                      removed="#FF333333"
                      Visibility="{Binding ElementName=rbExpReview, Path=IsChecked, Converter={StaticResource boolToVis}}">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="60" />
                        <!--stretch the image view to the width of the app-->
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <Border BorderThickness="1,1,1,1"
                            BorderBrush="#FFFFFFFF"
                            CornerRadius="12,12,12,12"
                            Margin="5"
                            VerticalAlignment="Top"
                            Grid.Column="0">
                        <ScrollViewer Name="scrollView"
                                      VerticalScrollBarVisibility="Auto"
                                      Margin="5">
                            <View:MasterView x:Name="MasterView" />
                        </ScrollViewer>
                    </Border>
                    <Border BorderThickness="1,1,1,1"
                            BorderBrush="#FFFFFFFF"
                            CornerRadius="12,12,12,12"
                            Margin="5"
                            VerticalAlignment="Top"
                            Grid.Column="1">
                        <Grid>
                            <ScrollViewer Name="scrollViewImage"
                                          VerticalScrollBarVisibility="Visible"
                                          Visibility="{Binding Path=ViewType, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource ViewTypeConverter}, ConverterParameter=0}"
                                          Margin="5">
                                <View:ImageView x:Name="ImageView" />
                            </ScrollViewer>
                            <StackPanel Name="stackPanelVolume"
                                        Visibility="{Binding Path=ViewType, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource ViewTypeConverter}, ConverterParameter=1}"
                                        Margin="5">
                                <View:VolumeControlView x:Name="volumeView" HorizontalAlignment="Stretch"/>
                            </StackPanel>
                        </Grid>
                    </Border>
                    <Border Grid.Column="2" >
                        <StackPanel>
                            <View:ToolBarView x:Name="toolBarView"/>
                            
                        </StackPanel>
                    </Border>
                </Grid>
                <Grid x:Name="dzGrid"
                      Visibility="{Binding ElementName=rbExpReviewDZ, Path=IsChecked, Converter={StaticResource boolToVis}}">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                        <!--stretch the web browser to the width of the app-->
                    </Grid.ColumnDefinitions>
                    <Border BorderThickness="1,1,1,1"
                            BorderBrush="#FFFFFFFF"
                            CornerRadius="12,12,12,12"
                            Margin="5"
                            VerticalAlignment="Top"
                            Grid.Column="0">
                        <StackPanel>
                            <Button x:Name="btnSelectExperiment"
                                    Width="120"
                                    Height="40"
                                    Content="Select Experiment"
                                    Margin="5"
                                    Click="btnSelectExperiment_Click" />
                            <TextBlock x:Name="txtSelectedExperiment"
                                   Text="None"
                                       Width="200"
                                   Margin="5" 
                                       Foreground="White"
                                       TextWrapping="Wrap"/>
                            <Canvas Width="100"
                                    Height="100"><!--Define a boundary to enclose the control-->
                                <Spin:SpinnerProgressControl x:Name="spinProgress"
                                                             SpinnerHeight="100"
                                                             SpinnerWidth="100" />
                            </Canvas>
                        </StackPanel>
                    </Border>
                    <Border BorderThickness="1,1,1,1"
                            BorderBrush="#FFFFFFFF"
                            CornerRadius="12,12,12,12"
                            Margin="5"
                            VerticalAlignment="Top"
                            Grid.Column="1">
                        <ScrollViewer VerticalScrollBarVisibility="Hidden"
                                      Margin="5">
                            <WebBrowser x:Name="webBrowser"
                                        Margin="5" />
                        </ScrollViewer>
                    </Border>
                </Grid>
                <Border BorderThickness="1,1,1,1"
                        BorderBrush="#FFFFFFFF"
                        CornerRadius="12,12,12,12"
                        Margin="5"
                        VerticalAlignment="Top"
                        Grid.Column="1"
                        Visibility="{Binding ElementName=rbSIReview, Path=IsChecked, Converter={StaticResource boolToVis}}">
                    <StackPanel Name="stForGrid">
                        <ScrollViewer Width="1024"
                                      Height="Auto"
                                      Margin="5"
                                      Name="sv"
                                      HorizontalScrollBarVisibility="Visible"
                                      VerticalScrollBarVisibility="Hidden"
                                      CanContentScroll="False"
                                      VerticalAlignment="Top"
                                      HorizontalAlignment="Center"></ScrollViewer>
                        <StackPanel Orientation="Horizontal"
                                    Width="1000"
                                    Height="100">
                            <Button Name="butOpen"
                                    Content="Open"
                                    Click="butOpen_Click"
                                    Width="100"
                                    Height="70"
                                    Margin="5"></Button>
                            <ScrollViewer Height="90"
                                          Margin="5"
                                          VerticalAlignment="Bottom"
                                          Name="svthumbnails"
                                          HorizontalScrollBarVisibility="Visible"
                                          VerticalScrollBarVisibility="Visible"
                                          CanContentScroll="False"
                                          HorizontalAlignment="Left">
                                <StackPanel Orientation="Horizontal"
                                            Height="80"
                                            Name="imagesStack" />
                            </ScrollViewer>
                        </StackPanel>
                    </StackPanel>
                </Border>
            </Grid>
        </StackPanel>
    </Grid>
</UserControl>


Nick
Posted
Updated 31-Oct-12 7:47am
v2

1 solution

So bind the radiobutton state to some property in the view model, and also bind the visibility property of the listbox item to the same property and use a visibility converter to control it's visibility, returning Visibilty.Collapse for one state and Visibility.Visible for the other. Here is link to creating a visibility converter: http://www.jeff.wilcox.name/2008/07/visibility-type-converter/[^]
 
Share this answer
 
v2
Comments
Nick Tsui 31-Oct-12 13:18pm    
I am not sure what button is used. That is why I pasted the code how the three buttons are created.
Clifford Nelson 31-Oct-12 13:31pm    
Then I need to see the code for the another button: "So, in the same user interface, there is another button, which when it is clicked, this pre-defined toolbar will show up, like following:" That is the button that needs to be the "ToggleButton"
Nick Tsui 31-Oct-12 13:48pm    
Code is up. Only the lines I mentioned is to call the pre-defined toolbar.

I think it is a radio button.

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