在wpf中.cs文件无法调用xaml中定义的空间名称解决方法
在wpf中.cs文件无法调用xaml中定义的空间名称
小弟刚刚接触wpf,现在遇见的问题如下:在LLKImage,.xamll中我定义了一个storyboard,设置它的name为sbFlash,但是现在在LLKImage.cs中调用时显示sbFlash无法识别。在此请问各位大侠:这是什么原因?
xaml中部分的代码如下:
<UserControl x:Class="LLK.LLKImage"
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:LLK"
mc:Ignorable="d"
d:DesignWidth="300">
<UserControl.Resources>
<local:PicTypeImageSrcValueConverter x:Key="picTypeImgSrcConverter">
</local:PicTypeImageSrcValueConverter>
<local:boolVisibleValueConverter x:Key="boolVisConverter">
</local:boolVisibleValueConverter>
<Storyboard x:Key="sbFlash" x:Name="sbShan" >
<DoubleAnimation Storyboard.TargetName="transformImg"
Duration="00:00:00.500" AutoReverse="True" RepeatBehavior="Forever">
</DoubleAnimation>
</Storyboard>
------解决方案--------------------
设置它的name为sbFlash 它的name是x:Name="sbShan"
------解决方案--------------------
资源在后台不是这样调用的 ,应该是调用FindResource方法 :
this.FindResource("sbShan");
或者
this.Resources["sbShan"];
小弟刚刚接触wpf,现在遇见的问题如下:在LLKImage,.xamll中我定义了一个storyboard,设置它的name为sbFlash,但是现在在LLKImage.cs中调用时显示sbFlash无法识别。在此请问各位大侠:这是什么原因?
xaml中部分的代码如下:
<UserControl x:Class="LLK.LLKImage"
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:LLK"
mc:Ignorable="d"
d:DesignWidth="300">
<UserControl.Resources>
<local:PicTypeImageSrcValueConverter x:Key="picTypeImgSrcConverter">
</local:PicTypeImageSrcValueConverter>
<local:boolVisibleValueConverter x:Key="boolVisConverter">
</local:boolVisibleValueConverter>
<Storyboard x:Key="sbFlash" x:Name="sbShan" >
<DoubleAnimation Storyboard.TargetName="transformImg"
Duration="00:00:00.500" AutoReverse="True" RepeatBehavior="Forever">
</DoubleAnimation>
</Storyboard>
------解决方案--------------------
设置它的name为sbFlash 它的name是x:Name="sbShan"
------解决方案--------------------
资源在后台不是这样调用的 ,应该是调用FindResource方法 :
this.FindResource("sbShan");
或者
this.Resources["sbShan"];