静态资源无法解析 [英] Static Resource could not be resolved

查看:226
本文介绍了静态资源无法解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨..
当试图实现用于将样式应用于文本框的资源标签时.得到以下错误:资源"MyTextBoxStyle"无法解析".我的表单的Xaml代码如下所示
< Window.Resources>
< ResourceDictionary>
< Style TargetType ="{x:Type TextBox}" x:Key ="MyTextBoxStyle">
< Setter Property ="Effect">
< Setter.Value>
< CornerRadius BottomLeft ="5"
BottomRight ="5"
TopLeft ="5"
TopRight ="5"></CornerRadius>
</Setter.Value>
</Setter>
< Setter Property ="Effect">
< Setter.Value>
< Border BorderBrush ="Black" BorderThickness ="2"></Border>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
</Window.Resources>
在我的文本框中,我将该资源用于以下用途:
< Grid>
< TextBox x:Name ="txtValues" Height ="25" Width ="80" BorderThickness ="1" Style ="{StaticResource MyTextBoxStyle}">
< Grid>

Hi..
when am trying to implement Resources tag for applying style to a Textbox.. am getting the following error: ''The resource "MyTextBoxStyle" could not be resolved''. The Xaml code for my form is as follows
<Window.Resources>
<ResourceDictionary>
<Style TargetType="{x:Type TextBox}" x:Key="MyTextBoxStyle">
<Setter Property="Effect">
<Setter.Value>
<CornerRadius BottomLeft="5"
BottomRight="5"
TopLeft="5"
TopRight="5"></CornerRadius>
</Setter.Value>
</Setter>
<Setter Property="Effect">
<Setter.Value>
<Border BorderBrush="Black" BorderThickness="2"></Border>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
</Window.Resources>
and in my textbox i have used that resource as the following:
<Grid>
<TextBox x:Name="txtValues" Height="25" Width="80" BorderThickness="1" Style="{StaticResource MyTextBoxStyle}">
<Grid>

could anybody help me to resolve the error..

推荐答案

您提供的xaml会抱怨很多,但不会抱怨无法解决的资源.

1)您在样式中两次设置了Effect .
2)您要将Effect设置为CornerRadius,然后设置Border实例,但是属性Effect的类型为
The xaml you provide will complain about alot but not about a resource that cannot be resolved.

1) You''re setting Effect twice in your style.
2) you''re setting Effect to a CornerRadius and then a Border instance, but the property Effect is of the type Effect[^]
3) you''ll need to close the TextBox tag <TextBox ... />
4) you''ll need to close the Grid tag <Grid><TextBox.../></Grid>

once you cleared that up it will compile


这篇关于静态资源无法解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆