gpt4 book ai didi

c# - 访问样式元素

转载 作者:太空宇宙 更新时间:2023-11-03 15:05:13 24 4
gpt4 key购买 nike

我有一个 slider 样式(剪切版)

<Style x:Key="SliderThumb" TargetType="Thumb">
<Setter Property="SnapsToDevicePixels" Value="true" />
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Thumb">
<Ellipse Height="15" Width="15" Fill="White"></Ellipse>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<ControlTemplate x:Key="Slider" TargetType="Slider">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" MinHeight="{TemplateBinding MinHeight}" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Track Grid.Row="1" x:Name="PART_Track" >
<Track.DecreaseRepeatButton>
<RepeatButton Style="{StaticResource SliderRepeatButton1}" Command="Slider.DecreaseLarge" />
</Track.DecreaseRepeatButton>
<Track.Thumb>
<Thumb Style="{StaticResource SliderThumb}" />
</Track.Thumb>
<Track.IncreaseRepeatButton>
<RepeatButton Style="{StaticResource SliderRepeatButton}" Command="Slider.IncreaseLarge" />
</Track.IncreaseRepeatButton>
</Track>
</Grid>
</ControlTemplate>

<Style x:Key="BigSliderStyle" TargetType="Slider">
<Setter Property="Focusable" Value="False"/>
<Setter Property="SnapsToDevicePixels" Value="true" />
<Setter Property="OverridesDefaultStyle" Value="true" />
<Style.Triggers>
<Trigger Property="Orientation" Value="Horizontal">
<Setter Property="MinHeight" Value="21" />
<Setter Property="MinWidth" Value="104" />
<Setter Property="Template" Value="{StaticResource Slider}" />
</Trigger>
</Style.Triggers>
</Style>

在我的界面中,我将其创建为

<Slider Style="{StaticResource BigSliderStyle}"/>

我只需要将工具提示绑定(bind)到与椭圆相关的 slider 缩略图。有什么方法可以从 XAML 表单中访问椭圆属性吗?

最佳答案

这应该可以解决您的问题:

<Style x:Key="SliderThumb" TargetType="Thumb">
<Setter Property="SnapsToDevicePixels" Value="true" />
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="ToolTip"><!--just add this part to your code-->
<Setter.Value>
<TextBlock Text="Some text"/><!-- also you can use Text="{Binding propertyName}"-->
</Setter.Value>
</Setter><!--just add this part to your code-->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Thumb">
<Ellipse Height="15" Width="15" Fill="White"></Ellipse>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

您已经可以通过样式访问缩略图。该元素支持开箱即用的工具提示,因此无需关注 ellipse,因为它只是 thumb 占位符的模板。< br/>这也将允许您为 Slider 使用不同的模板,让您在整个应用程序中保持 ToolTip

关于c# - 访问样式元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43905328/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com