dynamicresource

Is it possible to bind a DynamicResource of clr:string to another source instead of literal?

微笑、不失礼 提交于 2019-12-12 02:01:41
问题 <Window x:Class="WpfTutorialSamples.WPF_Application.ResourceSample" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=mscorlib"> <Window.Resources> <sys:String x:Key="centralRes">Hello, world!</sys:String> </Window.Resources> <StackPanel Margin="10"> <TextBox Name="src" /> <TextBlock Name="dst" Text="{DynamicResource centralRes}" FontSize="56" /> </StackPanel> </Window> I am just

WPF performance impact ResourceDictionary merging vs updating

被刻印的时光 ゝ 提交于 2019-12-11 16:16:13
问题 I have to update font size dynamically in WPF app. Performance wise which is a better approach or what are pros & cons of below 2 approaches? Merging dictionary [see API OnFontSizeChanged_MergeDictionary] Updating Resource Key [see API OnFontSizeChanged_UpdateResourceKey] I have defined all used FontSizes in GenericResourceDictionary.xaml: <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:System=

How to make a WPF resource be recalculated when a trigger's run?

狂风中的少年 提交于 2019-12-10 19:35:49
问题 In short: I've got a Style . It uses TemplateBinding a fair bit to make it parametrized instead of repeating myself over and over again. However, when a trigger for that style gets used and a resource gets used in a setter in that trigger, it just doesn't show up! Not even the default value gets shown. Here's a small program that replicates this issue: TestDictionary.xaml <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft

Set Style for user control

 ̄綄美尐妖づ 提交于 2019-12-09 19:00:42
问题 I am trying to set a style for my user control. The UserControl is in a project "Controls" and the theme is in a project "MainProject" <UserControl x:Class="Controls.OutputPanel" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" x:Name="OutputControl"> <!-- Style="

How do I duplicate a resource reference in code behind in WPF?

≯℡__Kan透↙ 提交于 2019-12-08 04:18:18
问题 In my application, I have a color resources. I have one element that uses that color as a dynamic resource in xaml. <Window x:Class="ResourcePlay.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="425"> <Window.Resources> <Color x:Key="MyColor">Red</Color> </Window.Resources> <Grid> <Rectangle VerticalAlignment="Top" Width="80" Height="80" Margin="10"> <Rectangle.Fill>

Return a dynamic resource from a converter

喜欢而已 提交于 2019-12-05 07:06:33
I want to change the color of a WPF control depending on the state of a bool, in this case the state of a checkbox. This works fine as long as I'm working with StaticResources: My control <TextBox Name="WarnStatusBox" TextWrapping="Wrap" Style="{DynamicResource StatusTextBox}" Width="72" Height="50" Background="{Binding ElementName=WarnStatusSource, Path=IsChecked, Converter={StaticResource BoolToWarningConverter}, ConverterParameter={RelativeSource self}}">Status</TextBox> My converter: [ValueConversion(typeof(bool), typeof(Brush))] public class BoolToWarningConverter : IValueConverter {

WPF StaticResource works, DynamicResource doesn't

心已入冬 提交于 2019-12-04 19:31:42
问题 I have been trying for a day now, to no avail, to create a bunch of brushes in the theme then using them with DynamicResource in a custom control. What I did is this: create the theme generic.xaml which contains styles (works) add a dictionary to merge in generic.xaml to contain brushes used in the application (works) make brushes have ComponentResourceKey keys (works) make control use brushes as static resource (works) make control use brushes as dynamic resource (DOESN'T WORK, the resource

Create your own system colors

柔情痞子 提交于 2019-12-04 12:59:43
Basically, how can I create my own set of Colors in a static class or the such so that I can do something like this: What exists : <Setter ... Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/> What I want : <Setter ... Value="{DynamicResource {x:Static MyColors.Color1}}"/> Resource Keys can be anything, so you can use a Color as a key and value at the same time: public static class MyColors { static MyColors() { App.Current.Resources.Add(MyHighlightColorKey, MyHighlightColorKey); } public static readonly Color MyHighlightColorKey = Color.FromArgb(255, 0, 88, 0); } The static

Set Style for user control

蹲街弑〆低调 提交于 2019-12-04 12:11:15
I am trying to set a style for my user control. The UserControl is in a project "Controls" and the theme is in a project "MainProject" <UserControl x:Class="Controls.OutputPanel" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" x:Name="OutputControl"> <!-- Style="{DynamicResource UserControlStyle}"> - I cant set the style here because the Resource Dictionary hasn't been

WPF StaticResource works, DynamicResource doesn't

こ雲淡風輕ζ 提交于 2019-12-03 12:40:21
I have been trying for a day now, to no avail, to create a bunch of brushes in the theme then using them with DynamicResource in a custom control. What I did is this: create the theme generic.xaml which contains styles (works) add a dictionary to merge in generic.xaml to contain brushes used in the application (works) make brushes have ComponentResourceKey keys (works) make control use brushes as static resource (works) make control use brushes as dynamic resource (DOESN'T WORK, the resource trace source says as much: System.Windows.ResourceDictionary Warning: 9 : Resource not found; ) add in