更改XAML中的预定义工具栏? [英] Changing pre-defined toolbar in xaml?

查看:68
本文介绍了更改XAML中的预定义工具栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的人们:

我是C#C ++项目中用于用户界面的一些xaml文件.我有预定义的工具栏,如下所示:

Dear Folks:

I am some xaml file for user interface in my C# C++ project. I have toolbar which is pre-defined as follows:

<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:



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:

<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;
非常感谢.
Here is the entire code of the button that loads the pre-defeined:


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:

<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



Nick

推荐答案

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/[^]
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/[^]


这篇关于更改XAML中的预定义工具栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆