是否可以使用值转换器而无需事先将它们定义为资源?
现在我有
<Window.Resources>
<local:TrivialFormatter x:Key="trivialFormatter" />
</Window.Resources>
Run Code Online (Sandbox Code Playgroud)
和
<Button Width="{Binding Width,
ElementName=textBox1,
UpdateSourceTrigger=PropertyChanged,
Converter={StaticResource trivialFormatter}}">
Run Code Online (Sandbox Code Playgroud)
那岂不是可能的,而不必申报Window.Resources的trivialFormatter资源,我可以直接从按钮的宽度结合参考呢?就像是
Converter = {local:TrivialFormatter}
Run Code Online (Sandbox Code Playgroud)
谢谢
我有以下代码:
<Color x:Key="SelectedColor">Gold</Color>
Run Code Online (Sandbox Code Playgroud)
以及包含颜色的TabItem样式
<VisualState x:Name="Selected">
<Storyboard>
<ColorAnimationUsingKeyFrames
Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[0].(GradientStop.Color)"
Storyboard.TargetName="InnerRectangle2">
<EasingColorKeyFrame KeyTime="0" Value="{DynamicResource SelectedColor}"/>
</ColorAnimationUsingKeyFrames>
Run Code Online (Sandbox Code Playgroud)
事实证明我不能使用DynamicResource一个EasingColorKeyFrame.
我能做些什么来达到我的效果?
我需要动态设置颜色,所以才换"{DynamicResource SelectedColor}"用"{StaticResource SelectedColor}"是假表.
我已经创建了一个很小的解决方案来演示这个问题 - Selected Tab应该是Gold color,但它实际上是透明的,因为我猜VSM无法解析名为" SelectedColor" 的颜色