是否有人认为打开资源字典的xaml默认为Design和Xaml的分屏是有点蹩脚的?
我缺少一个设置吗?或者这只是MS告诉我购买Blend的方式......
干杯,
Berryl
我想在一个独立的dll中包含一组样式,可以从许多不同的WOF类中引用它们来定义常见样式.
我已经创建了独立的dll并尝试引用它但是遇到了问题.
这是独立dll的代码:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="myStyle" TargetType="Button">
<Setter Property="Background" Value="Orange" />
<Setter Property="FontStyle" Value="Italic" />
<Setter Property="Padding" Value="8,4" />
<Setter Property="Margin" Value="4" />
</Style>
<!-- store here your styles -->
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)
这是我试图引用它的地方:
<src:GX3ClientPlugin.Resources>
<ResourceDictionary Source="pack://application:,,,/GX3StyleResources.dll;component/GX3StyleResources.xaml" />
</src:GX3ClientPlugin.Resources>
Run Code Online (Sandbox Code Playgroud)
运行时,我得到以下异常:
无法加载文件或程序集"GX3StyleResources.dll,Culture = neutral"或其依赖项之一.该系统找不到指定的文件.
有任何想法吗?
我有Class Library以下代码位。
以下是我UserControl的Resource:
<UserControl.Resources>
<ResourceDictionary Source="pack://application:,,,/Mine.Controls;component/Templates.xaml" />
</UserControl.Resources>
Run Code Online (Sandbox Code Playgroud)
下面是我的ResourceDictionary名为Templates.xaml 的文件:
构建操作:资源
复制到...:不要复制
自定义工具:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ControlTemplate x:Key="MyButton"
TargetType="Button">
<Border x:Name="buttonBorderOuter"
BorderBrush="#DBDBDB"
BorderThickness="1"
Background="#00ECECEC"
CornerRadius="5" />
</ControlTemplate>
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)
然后我得到错误
异常:查找资源字典“pack://application:,,,/Mine.Controls;component/Templates.xaml”时发生错误。
我究竟做错了什么?
我从string.Format(...)操作中收到以下错误:
System.FormatException - 输入字符串的格式不正确.
我有一个资源字典,其中包含一个带有基本html页面的条目.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title of the document</title>
<style>
* {
margin: 0;
padding: 0;
}
body {
font-family: 'Arial, Verdana', Fallback, sans-serif;
font-size: 14px;
}
table {
background-color: #eeeeee;
width: 100%;
padding: 10px;
margin: 5px;
}
h1 {
font-size: 16px;
font-weight: bold;
margin: 20px 0 10px 0;
}
</style>
</head>
<body>
text<br />
<table>
<tr>
<td>Text 1</td>
<td>{0}</td>
</tr>
<tr>
<td>Text 2</td>
<td>{1}</td>
</tr>
<tr>
<td>Text 3</td>
<td>{2}</td>
</tr>
<tr> …Run Code Online (Sandbox Code Playgroud) 我正在通过 x: UID 属性翻译我的 UWP 应用程序。
代码(XAML):
<NavigationViewItem x:Name="Assistant_Mode" x:Uid="Assistant_Header" Content="Asistan modu" Tag="assistant" ToolTipService.ToolTip="Asistan modu." FontFamily="Segoe UI">
Run Code Online (Sandbox Code Playgroud)
资源字典记录:
Assistant_Header.Content: Asistan modu
现在,我想通过资源字典翻译 ToolTipService.ToolTip 但这个键盘在字典中不起作用:
Assistant_Header.ToolTipService.ToolTip: Asistan modu
我可以翻译资源字典中的工具提示吗?谢谢。
resourcedictionary windows-10 uwp windows-10-universal uwp-xaml
所以我不明白这是怎么发生的,但我在资源字典中定义了一个按钮样式并在其中加载了该字典Windows.Resources.
但它并不适用于我想要的所有按钮,只适用于最后一个元素.
风格:
<Style TargetType="{x:Type Button}" x:Key="FolderOpenBtn">
<Setter Property="Content">
<Setter.Value>
<StackPanel Orientation="Horizontal">
<Viewbox Width="16" Height="16" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Margin="0,0,2,0">
<Rectangle Width="16" Height="16">
<Rectangle.Fill>
<DrawingBrush>
<DrawingBrush.Drawing>
<DrawingGroup>
<DrawingGroup.Children>
<GeometryDrawing Brush="#00FFFFFF" Geometry="F1M0,0L16,0 16,16 0,16z" />
<GeometryDrawing Brush="#FFF6F6F6" Geometry="F1M0,2.9688L0,11.9688C0,12.5858 0.227,13.0718 0.57,13.4038 1.14,13.9478 2,13.9688 2,13.9688L13.677,13.9688 16,8.1648 16,6.9688 15,6.9688 15,4.9688C15,3.6698,13.97,2.9688,13,2.9688L10.116,2.9688 9.116,0.9688 2,0.9688C1.005,0.9688,0,1.6658,0,2.9688" />
<GeometryDrawing Brush="#FFEFEFF0" Geometry="F1M2,3L8,3 9,5 13,5 13,8 4,8 2,13z" />
<GeometryDrawing Brush="#FF424242" Geometry="F1M1,3L1,12C1,12.97,1.94,12.984,1.997,12.984L2,12.984 2,3 8,3 9,5 13,5 13,8 4,8 2,13 13,13 15,8 14,8 14,5C14,4,12.764,4,13,4L9.5,4 8.5,2 2,2C2,2,1,2,1,3" />
</DrawingGroup.Children>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</Rectangle.Fill>
</Rectangle> …Run Code Online (Sandbox Code Playgroud) 我有以下问题:我想访问XAML资源中定义的这三个变量之一
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../../Themes/MainStyle.xaml" />
</ResourceDictionary.MergedDictionaries>
<System:Int32 x:Key="maxVal">500</System:Int32>
<System:Int32 x:Key="minVal">250</System:Int32>
<System:Int32 x:Key="actualWidth">250</System:Int32>
</ResourceDictionary>
</UserControl.Resources>
Run Code Online (Sandbox Code Playgroud)
我想像这样从Codebehind文件访问“ actualWidth”的值:
private void MinMaxGraphicsMessageSink(bool minmax)
{
actualWidth = minmax ? 900 : 300;
}
Run Code Online (Sandbox Code Playgroud)
但这是行不通的。有人可以帮忙吗?
我想把我目前拥有的xaml用于ComboBox(下面),并将其浓缩成类似Style的内容,如下所示.我认为这应该有效,但我有一个'类型'问题,不知道如何解决它
"Cannot resolve the Style Property 'Margin'. Verify that the owning type is the Style's TargetType, or use Class.Property syntax to specify the Property.)
Run Code Online (Sandbox Code Playgroud)
当我看到现有的ComboBoxStyle(也在下面)我希望将这种新风格作为基础时,我看到我没有使用x:Type,但它似乎确实有效.
这种新风格应该不起作用吗?我该改变什么?
干杯,
Berryl
组合框,工作):
<ComboBox
x:Name="cboDepartmentFilter" Style="{StaticResource ComboBoxStyle}"
Margin="{StaticResource FliterPanelItem_Margin}" Width="{StaticResource FilterPanelItem_Width}"
ItemsSource="{Binding Path=DepartmentFilterControl.Choices}"
ToolTip="{Binding DepartmentFilterControlData.ToolTipTitle}"
/>
Run Code Online (Sandbox Code Playgroud)
我想要的是:
<ComboBox Style="{StaticResource FilterPanelComboBoxStyle}" DataContext="{Binding DepartmentFilterControl}" />
<!- in some resource file ->
<Style x:Key="FilterPanelComboBoxStyle" BasedOn="{StaticResource ComboBoxStyle}">
<Setter Property="Margin" Value="{StaticResource FliterPanelItem_Margin}" />
<Setter Property="Width" Value="{StaticResource FilterPanelItem_Width}" />
<Setter Property="ItemsSource" Value="{Binding Choices}" />
<Setter Property="ToolTip" Value="{Binding ToolTipTitle}" …Run Code Online (Sandbox Code Playgroud) 我定义了一个静态资源:
<UserControl x:Class="MyProject.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d"
Width="255"
Height="300">
<UserControl.Resources>
<sys:Double x:Key="CornerRadiusValue">5</sys:Double>
</UserControl.Resources>
...
Run Code Online (Sandbox Code Playgroud)
稍后在 XAML 文件中,我尝试在为边框设置左上角半径时使用该值:
<Border
Width="40"
Height="30"
BorderThickness="1,1,0,0"
BorderBrush="Red">
<Border.CornerRadius>
<CornerRadius TopLeft="{StaticResource CornerRadiusValue}" />
</Border.CornerRadius>
</Border>
Run Code Online (Sandbox Code Playgroud)
在设计时,一切正常,更改CornerRadiusValue静态资源的值会更改边框上的角半径。但是,当我想运行它时,我收到一条XamlParseException消息异常:
无法设置只读属性“System.Windows.CornerRadius.TopLeft”。
我究竟做错了什么?我如何使它工作?谢谢。
我在XAML中用代码隐藏了一个ResouceDictionary。我需要使用鼠标事件和数据绑定定义一些特定于视图的行为,为此,我需要访问在DataTemplate内部定义的某些元素。
问题是,DataTemplate没有Key,而只有TargetType(这是必需的,因此WPF会自动将其用于给定类型)。
那么,如何从代码隐藏访问DataTemplate?
编辑:
如果在构造函数中的某个地方放置断点,则可以看到ViewModel的模板在那里。似乎ResourceDictionary.Keys属性是一个对象数组,而我要访问的键(实际上是相应的值)在调试器中是这样的:
{DataTemplateKey(Company.Application.ViewModels.TargetViewModel)}
Run Code Online (Sandbox Code Playgroud)
XAML:
<sys:Double x:Key="escala">10</sys:Double>
<sys:Double x:Key="raio">20</sys:Double>
<EllipseGeometry x:Key="geometriacirculo"
RadiusX="{StaticResource raio}"
RadiusY="{StaticResource raio}"/>
<ScaleTransform x:Key="transform" ScaleX="{StaticResource escala}" ScaleY="{StaticResource escala}" />
<ap:NormalConverter x:Key="NormalConverter"/>
<ap:BitmapToSource x:Key="BitmapToSource"/>
<DataTemplate DataType="{x:Type vm:TelaColetaViewModel}">
<.....
Run Code Online (Sandbox Code Playgroud)
代码背后:
public partial class TelaColetaTemplate : ResourceDictionary
{
EllipseGeometry _geometria_circulo;
ScaleTransform _scale_transform;
Grid GridZoom;
Path CirculoGuia;
double _escala;
Point? _ponto_clicado_norm;
public TelaColetaTemplate()
{
InitializeComponent();
// three following lines work, accessing them with key, no problem
_geometria_circulo = (EllipseGeometry)this["geometriacirculo"];
_scale_transform = (ScaleTransform)this["transform"];
_escala = (double)this["escala"];
//var wantedTemplate = ???? …Run Code Online (Sandbox Code Playgroud) 为了清理我的代码,我正在尝试将app.xaml拆分为单独的资源字典.这适用于运行时,但不适用于设计时:
剪辑在app.xaml
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/;component/Theme/Colors.xaml" />
<ResourceDictionary Source="/;component/Theme/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Run Code Online (Sandbox Code Playgroud)
Colors.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<SolidColorBrush x:Key="backgroundBrush" Color="Gold"/>
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)
Styles.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="StatusBar">
<Setter Property="Background" Value="{StaticResource backgroundBrush}" />
</Style>
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)
剪切了MainWindow.xaml
<Window x:Class="test.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="test" Width="800" Height="600" >
<StatusBar Name="statusBar" DockPanel.Dock="Bottom">
<StatusBarItem Content="{Binding statusMessage}" />
</StatusBar>
Run Code Online (Sandbox Code Playgroud)
DesignView给出错误:错误8'{DependencyProperty.UnsetValue}'不是属性'Background'的有效值.C:\ Daten\DotNet\test\test\MainWindow.xaml 123
如果我将backgroundBrush直接放入app.xaml中,如下所示:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/;component/Theme/Colors.xaml" />
<ResourceDictionary Source="/;component/Theme/Styles.xaml" />
<ResourceDictionary>
<SolidColorBrush x:Key="backgroundBrush" Color="Gold"/>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Run Code Online (Sandbox Code Playgroud)
DesignView没有问题.
那么有没有办法告诉DesignView在哪里找到backgroundBrush,如果这个画笔放在一个单独的资源字典中?
是否可以将相同的样式设置为多个控件?我尝试了以下方式.但第一个按钮样式未正确应用,第二个样式应用正常.
设计:
<StackPanel Orientation="Horizontal">
<TextBlock Foreground="White" Margin="0,0,5,0">1st Button</TextBlock>
<Button Style="{StaticResource ViewButton}" />
<TextBlock Foreground="White" Margin="25,0,5,0">2nd Button</TextBlock>
<Button Style="{StaticResource ViewButton}" />
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
资源:
<Style x:Key="ViewButton" TargetType="Button" BasedOn="{StaticResource ButtonStyle}">
<Setter Property="Content">
<Setter.Value>
<StackPanel Orientation="Horizontal">
<Image Source="/Images/View.png" Stretch="None" Width="24" Height="24" />
<TextBlock Margin="5,0,0,0" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold">View</TextBlock>
</StackPanel>
</Setter.Value>
</Setter>
<Setter Property="Padding" Value="2,0,10,0"/>
</Style>
Run Code Online (Sandbox Code Playgroud)
我在模板中使用 DynamicResource,并在使用该模板的每个样式中使用 StaticResourceExtensions 作为资源,以便在每个样式中对 DynamicResource 进行不同的评估。
问题是,我收到此错误:
Unable to cast object of type 'System.Windows.Media.Effects.DropShadowEffect' to type 'System.Windows.ResourceDictionary'
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
<DropShadowEffect
x:Key="Sombra"
Opacity="0.5"
ShadowDepth="3"
BlurRadius="5"
/>
<ControlTemplate
x:Key="ControleGeometriaTemplate"
TargetType="{x:Type Control}"
>
<Border
x:Name="border"
Background="{TemplateBinding Background}"
Width="{TemplateBinding Width}"
Height="{TemplateBinding Height}"
/>
<Path
x:Name="ícone"
Fill="{TemplateBinding Foreground}"
Effect="{DynamicResource PathShadow}"
/>
</Border>
</ControlTemplate>
<Style x:Key="BotãoGeometria" TargetType="{x:Type ButtonBase}">
<Setter Property="Template" Value="{StaticResource ControleGeometriaTemplate}"/>
</Style>
<Style
x:Key="BotãoNavegaçãoBase"
TargetType="{x:Type ButtonBase}"
BasedOn="{StaticResource BotãoGeometria}"
>
<Style.Resources>
<StaticResource x:Key="PathShadow" ResourceKey="Sombra"/>
</Style.Resources>
</Style>
Run Code Online (Sandbox Code Playgroud) wpf ×10
xaml ×7
c# ×5
.net ×1
code-behind ×1
cornerradius ×1
designview ×1
resources ×1
silverlight ×1
string ×1
styles ×1
targettype ×1
uwp ×1
uwp-xaml ×1
windows-10 ×1