标签: controltemplate

如何更改 ControlTemplate 中标签的字体大小

在我的 WPF ListBox 中,我有一个带有 ListBoxItem 的 ControlTemplate 的样式。在那个 ControlTemplate 里面,我定义了一个标签。根据一些细节,我需要更改标签的字体大小。所以从我的代码隐藏中,我需要确定字体应该是什么,然后我需要设置它。

这是我使用 ControlTemplate 的风格(我去掉了一些不相关的控件)

<Style x:Key="RecordTabList" TargetType="{x:Type ListBoxItem}">
            <Setter Property="Background" Value="{DynamicResource RecordIndexTabBackcolor}" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate>        
                            <Label
                                x:Name="myLabel" Grid.Column="0" Grid.ColumnSpan="1" Grid.Row="0" Grid.RowSpan="1" Margin="3,-2,0,-2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Foreground="{DynamicResource RecordIndexTabForeground}" 
                                FontSize="10" Height="Auto" BorderThickness="3,0,0,0"
                                Content="{Binding Path=Name}" />
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

wpf controltemplate templatebinding

2
推荐指数
1
解决办法
2万
查看次数

如何将ControlTemplate Enabled属性绑定到WPF XAML中的Opacity

在XAML内部的WPF中,如何扩展ControlTemplate,当应用于按钮并且按钮被禁用时,它会在禁用时淡化为0.5不透明度,并且一旦启用就会淡化回1.0不透明度.

当父母被禁用时,此视觉效果也应该起作用.

c# wpf xaml opacity controltemplate

2
推荐指数
1
解决办法
5428
查看次数

Silverlight Bing地图图钉样式

有谁知道Bing Maps Silverlight控件的默认控件模板和XAML样式是否可用?我们喜欢默认的Pushpin控件的一般外观,但希望它们有多种颜色,而不仅仅是默认的橙色.似乎唯一容易或直接的方法是在我们的App.xaml中提供基于默认值的新ControlTemplate - 每种颜色一个.

没问题,除了我无法识别现有的默认控件模板.大多数核心Silverlight工具包控件都在MSDN上提供了默认样式,但我还没有找到Bing Maps API的样式.

谢谢,

杰夫

silverlight xaml controltemplate bing-maps pushpin

2
推荐指数
1
解决办法
958
查看次数

ComboBox ControlTemplate下拉按钮

我想知道是否有人举例说明如何设置/模板组合框只显示默认初始状态的按钮.有点像功能区栏的DropDownButton画廊.我希望用户能够单击按钮并列出组合框项目.选择后,它不会在文本字段中保存所选项目,因为没有文本字段只有一个按钮.谢谢 :)

wpf combobox styles controltemplate

2
推荐指数
1
解决办法
5029
查看次数

属性更改时更改自定义控件的内容模板

我是WPF的新手,我不知道该怎么做我想做的事.

我已经构建了一个自定义控件,我称之为音量控制.它有2个RepeatButtons,1个用于增加Volume属性的值,1个用于减少它,还有一个ProgressBar用于给出当前Volume的可视化表示.该控件具有Orientation类型的名为"Orientation"的属性.当它是水平的时候,我希望控制以一种方式绘制,当它是垂直时,我希望它看起来不同.

在水平模式下,控件将简单地将3个控件放在水平StackPanel中.垂直外观有点复杂,因为它有一个网格,有2列和2行.2个RepeatButtons在左侧堆叠在一起,而ProgressBar跨越两行并且在右侧.

我似乎无法弄清楚如何使控件根据Orientation属性的值更改其外观.这是我到目前为止所得到的:

<Style x:Key="Horizontal" TargetType="{x:Type cs:VolumeControl}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type cs:VolumeControl}">
                <StackPanel Orientation="Horizontal">
                    ...
                </StackPanel>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

<Style x:Key="Vertical" TargetType="{x:Type cs:VolumeControl}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type cs:VolumeControl}">
                <Grid>
                    ...
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)

我知道我需要这样的东西来定义默认模板和Orientation属性的必要触发器:

<Style TargetType="{x:Type cs:VolumeControl}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type cs:VolumeControl}">
                <ControlTemplate.Triggers>
                    <Trigger Property="Orientation" Value="Horizontal">
                        ???
                    </Trigger>

                    <Trigger Property="Orientation" Value="Vertical">
                        ???
                    </Trigger>

                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
        </Setter.Value>
    </Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)

我不知道在两个Trigger标签中加入什么来使它工作.或者即使我已经把它弄好了.

我查看了ProgressBar的模板,当Orientation设置为Vertical时,它使用RotationTransform垂直绘制控件.我不能这样做,因为意图是以不同的布局绘制控件.

任何帮助表示赞赏.

托尼

wpf custom-controls controltemplate

2
推荐指数
1
解决办法
2803
查看次数

是否可以将模板绑定到几何体

我目前有一个自定义控件Button,它DrawingImage通过类型的依赖属性在控件上显示一个集合ControlTemplate.我一直在尝试移动DrawingImage到控件模板并绑定到一个Geometry而不是失败.是否可以绑定到Geometry对象?如果不是,为什么不,如果是,我错过了什么?

下面的屏幕截图显示了我在右侧的成功尝试和左侧的失败尝试.

问题

绑定到DrawingImage的示例(有效) - generic.xaml:

<Style TargetType="{x:Type local:RoundButton3}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:RoundButton3}">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="auto"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>

                    <Ellipse StrokeThickness="5" Stroke="Green"/>

                    <Viewbox Margin="10" Stretch="Uniform">
                        <ContentControl 
                            Template="{TemplateBinding ImageTemplate}" />
                    </Viewbox>

                    <TextBlock VerticalAlignment="Center" 
                               Grid.Column="1" 
                               Text="Round Button" Margin="5,0,0,0" />
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)

public class RoundButton3 : Button
{
    static RoundButton3()
    {
        DefaultStyleKeyProperty.OverrideMetadata(
            typeof(RoundButton3), 
            new FrameworkPropertyMetadata(typeof(RoundButton3)));
    }

    public static readonly DependencyProperty ImageTemplateProperty =
        DependencyProperty.Register(
            "ImageTemplate", typeof …
Run Code Online (Sandbox Code Playgroud)

wpf xaml custom-controls controltemplate

2
推荐指数
1
解决办法
2084
查看次数

触发器没有绑定属性

在我阅读WPF期间,我遇到了一个问题,试图在模板中的Trigger上创建绑定,用于创建图像按钮.

<ControlTemplate x:Key="ToolbarButtonHover" TargetType="Button">
    <Grid Name="backgroundGrid">
        <Image Source="{DynamicResource ResourceKey=Img}" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}"></Image>
    </Grid>
    <ControlTemplate.Triggers>
        <Trigger Property="Button.IsPressed" Value="True">
            <Setter TargetName="backgroundGrid" Property="Background" Value="#007ACC" />
        </Trigger>
        <!--Error: The property 'Binding' was not found in type Trigger-->
        <Trigger Binding="{Binding Path=IsMouseOver, RelativeSource={RelativeSource TemplatedParent}}" Value="True">
            <Setter TargetName="backgroundGrid" Property="Background" Value="Red" />
        </Trigger>
    </ControlTemplate.Triggers>
</ControlTemplate>
Run Code Online (Sandbox Code Playgroud)

导致错误The property 'Binding' was not found in type Trigger,更具体地说<Trigger Binding="{ Path=IsMouseOver, RelativeSource={RelativeSource TemplatedParent}}" Value="True">是生成它的行 .

这个错误的原因是什么?

wpf binding controltemplate

2
推荐指数
1
解决办法
2162
查看次数

来自代码的访问控制

如果我有一个定义控件模板的样式,并且我有一个控件,让我们说一个按钮,有没有办法从样式控件后面的代码访问按钮?

感谢你们!=)

wpf styles code-behind controltemplate

2
推荐指数
1
解决办法
6023
查看次数

WPF:ControlTemplate的IsPressed触发器无法正常工作

我使用一个名为的自定义控件ImageButton来显示具有不同图像的按钮.ImageButton包含依赖属性:

public ImageSource DisabledImageSource
    {
        get { return (ImageSource)GetValue(DisabledImageSourceProperty); }
        set { SetValue(DisabledImageSourceProperty, value); }
    }


    public ImageSource NormalImageSource
    {
        get { return (ImageSource)GetValue(NormalImageSourceProperty); }
        set { SetValue(NormalImageSourceProperty, value); }
    }

    public ImageSource HoverImageSource
    {
        get { return (ImageSource)GetValue(HoverImageSourceProperty); }
        set { SetValue(HoverImageSourceProperty, value); }
    }

    public ImageSource PushedImageSource
    {
        get { return (ImageSource)GetValue(PushedImageSourceProperty); }
        set { SetValue(PushedImageSourceProperty, value); }
    }


    public static readonly DependencyProperty DisabledImageSourceProperty =
        DependencyProperty.Register("DisabledImageSource", typeof(ImageSource), typeof(ImageButton), new UIPropertyMetadata());


    public static readonly DependencyProperty …
Run Code Online (Sandbox Code Playgroud)

c# wpf custom-controls controltemplate

2
推荐指数
1
解决办法
8060
查看次数

仅当treeview具有绑定到它的项目时,如何使controltemplate中的控件可见

所以我有这个控制模板,我想要signalnamepanel(只是一个时间标签,我将在它旁边添加一个x轴)只有当项目绑定到Treeview时才会显示.

否则它看起来会很奇怪,因为namepanel会自动浮动.我猜我需要使用某种类型的触发器,但我不确定我会触发什么.

<Style x:Key="{x:Type TreeView}" TargetType="TreeView">
      <Setter Property="OverridesDefaultStyle" Value="True" />
      <Setter Property="SnapsToDevicePixels" Value="True" />
      <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
      <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="TreeView">

              <ScrollViewer 
                Focusable="False"
                CanContentScroll="False"
                Padding="4">
                <StackPanel>
                  <Grid>
                    <Grid.ColumnDefinitions>
                      <ColumnDefinition Width="19" />
                      <ColumnDefinition Width="*" />
                      <ColumnDefinition Width="{Binding ElementName=graph_viewer, Path=signal_graph_window_width, Mode=OneWay}" />
                    </Grid.ColumnDefinitions>
                    <wpfExp:SignalNamePanel Grid.Column="1"
                      Height="{Binding ElementName=graph_viewer, Path=GraphHeight, Mode=OneWay}"
                      MainText="Time" 
                    />
                    <wpfExp:SignalGraphAxis Grid.Column="2"
                      Height="{Binding ElementName=graph_viewer, Path=GraphHeight, Mode=OneWay}"                
                      PenWidth="{Binding ElementName=graph_viewer, Path=GraphPenWidth, Mode=OneWay}"
                      X_Scale="{Binding ElementName=graph_viewer, Path=X_Scale, Mode=OneWay}"
                      MaxTimeValue="{Binding ElementName=graph_viewer, Path=_SignalDataViewModel.MaxTimeValue, Mode=OneWay}"
                    />
                  </Grid>

                  <ItemsPresenter/>
                </StackPanel>
              </ScrollViewer>
            <ControlTemplate.Triggers>
              <Trigger Property="IsMouseOver"
                                   Value="True"> …
Run Code Online (Sandbox Code Playgroud)

wpf treeview xaml triggers controltemplate

1
推荐指数
1
解决办法
1390
查看次数