我正在制作usercontrol
库。因此我没有app.xaml
文件,也没有mainwindow.xaml
。用户控件在应用样式后不显示
我从另一个WPF项目导入(复制)滑块样式。这resource dictionary
设置为page
,并且以前工作正常,但是,只要我将它应用到我的滑块,然后该控件不显示在VisualStudio以及运行时。没有错误被抛出。
<UserControl x:Class="WPF.UserControls.CustomSlider"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WPF.UserControls"
x:Name="CustomSliderControl"
mc:Ignorable="d"
d:DesignHeight="407" d:DesignWidth="127">
<UserControl.Resources>
<ResourceDictionary Source="/WPFUserControls;component/Styles/BaseSliderStyle.xaml"/>
</UserControl.Resources>
<Grid>
<Slider x:Name="Hello" Style="{DynamicResource BaseSliderStyle}" Value="{Binding Value, Mode=TwoWay,
RelativeSource={RelativeSource AncestorType={x:Type local:CustomSlider}}}" Minimum="0.0" Maximum="1.0"/>
</Grid>
这里是滑盖造型的一部分:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPF.UserControls">
<Style x:Key="BaseSliderStyle" TargetType="{x:Type Slider}">
<Setter Property="Stylus.IsPressAndHoldEnabled" Value="false"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="Foreground" Value="{StaticResource SliderThumb.Static.Foreground}"/>
<Setter Property="Template" Value="{StaticResource SliderHorizontal}"/>
<Style.Triggers>
<Trigger Property="Orientation" Value="Vertical">
<Setter Property="Template" Value="{StaticResource SliderVertical}"/>
</Trigger>
</Style.Triggers>
</Style>
我可能会错过一些东西。任何提示?
感谢。
是WPFUserControls你的DLL /项目的名称? – GCamel
检查是否导入了 中的资源。另外检查SliderVertical是否被导入。 –