如何在WPF UserControl中创建样式?

如何在WPF UserControl中创建样式?,第1张

概述我想在我的UserControl上设置一些控件的样式,但似乎找不到正确的语法: <UserControl x:Class="HiideSRM.WIDSModule.BiometricStatusIndicator" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 我想在我的UserControl上设置一些控件的样式,但似乎找不到正确的语法:

<UserControl x:Class="HiIDeSRM.WIDSModule.BiometricStatusIndicator"                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"                >    <Style targettype="{x:Type border}">        <Setter  Property="WIDth" Value="10"/>     </Style>    <StackPanel OrIEntation="Horizontal" x:name="Panel">        <border Height="50" margin="1"/>        <border Height="10" margin="1"/>        <border Height="10" margin="1"/>        <border Height="10" margin="1"/>    </StackPanel></UserControl>
解决方法 首先,将您的样式放入.Resources标记 – 它可以是几乎任何控件标记的子代(例如,border,usercontrol,grID等)
第二,您可以在标记中指定样式,但由于您没有在资源上声明x:键,因此该样式将应用于此控件中的所有边框.

<UserControl.Resources>    <Style targettype="{x:Type border}">        <Setter  Property="WIDth" Value="10"/>     </Style></UserControl.Resources>

请注意,silverlight的语法不同.而不是targettype =“{x:Type border}”你会使用targettype =“border”

总结

以上是内存溢出为你收集整理的如何在WPF UserControl中创建样式?全部内容,希望文章能够帮你解决如何在WPF UserControl中创建样式?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1209363.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-04
下一篇2022-06-04

发表评论

登录后才能评论

评论列表(0条)

    保存