dynamicresource

Restore dynamic resource value

北城以北 提交于 2021-02-05 09:26:07
问题 I have a textblock tb with style. <TextBlock x:Name="tb" Style="{DynamicResource H1Style}" Text="Test"/> <Style TargetType="{x:Type TextBlock}" x:Key= "H1Style"> <Setter Property="FontSize" Value="18" /> <Setter Property="FontWeight" Value="Light"/> </Style> Then i change size tb.FontSize = 5; How do i restore style H1Style of tb? I tried set SetResourceReference , but FontSize still 5 instead of 18. tb.SetResourceReference(Control.StyleProperty, "H1Style"); 回答1: this line - tb.FontSize = 5;

Return a dynamic resource from a converter

冷暖自知 提交于 2020-01-13 09:19:11
问题 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:

Wpf dynamic resource lookup for Validation.ErrorTemplate

自古美人都是妖i 提交于 2020-01-07 09:29:40
问题 in my App.xaml I defined a resource for Validation.ErrorTemplate , which depends on dynamic BorderBrush resource. I intend to define unique BorderBrush in each window I have and also within different blocks inside window. <!--validation error template--> <ControlTemplate x:Key="NonValid"> <Border BorderBrush="{DynamicResource BorderBrush}" BorderThickness="2" Margin="5"> <AdornedElementPlaceholder x:Name="ui"/> </Border> </ControlTemplate> and this one to demonstrate my problem (also with

Create your own system colors

倾然丶 夕夏残阳落幕 提交于 2020-01-01 14:23:46
问题 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}}"/> 回答1: 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,

How to bind with dynamic resource and specifying a path

对着背影说爱祢 提交于 2020-01-01 03:07:08
问题 I want to bind to a resource (DynamicResource) and access properties on that resource, but is there a way to do that? (I want to visualize the default values from constructor in the xaml editor in visual studio. Those cannot be seen when referencing an object through DataContext nor through a property added on my Window class...) Not working xaml: (works in composer but not at runtime...) <Window ... > <Window.Resources> <local:MyClass x:Key="myResource" /> </Window.Resources> <StackPanel>

ComponentResourceKey as DynamicResource problem

别来无恙 提交于 2019-12-24 00:23:58
问题 I'm seeing some unexpected behavior using ComponentResourceKey. The problem came up because I was using names used in the SystemColors class. Consider the following code: First I expose a ComponentResourceKey in a as a static property: public enum ColorKeys { ControlColor } public class MyColors { public static ComponentResourceKey ControlColorKey { get { return new ComponentResourceKey(typeof(MyColors), ColorKeys.ControlColor); } } } Using the key in markup to assign a resource to that key

TextBlock foreground being reset to inherited value after dynamic resource from merged dictionary is applied

為{幸葍}努か 提交于 2019-12-22 11:29:17
问题 EDIT : I was able to reproduce this in a very stripped-down version of the application. Here is a link to the .zip file http://www.mediafire.com/?cn918gi15uph1xe I have the module add the view to two different regions - the status bar region along the top is where the issue occurs. The weird part is, when the same view type is added to the main region, there are no problems. The status bar region is an ItemsControl and the main region is a ContentPresenter. That is the only difference. Please

How are DynamicResources built and their use in contextmenus

穿精又带淫゛_ 提交于 2019-12-20 11:35:24
问题 Are dynamic resources truly dynamic? If I define a DynamicResource, I realise that an expression is created (where?) that is not translated into a resource until runtime, however, What I do not understans is whether this dynamicresouce, once built, is now "Static" For instance, if I create a context menu via a dynamicresource, are the menuitems which are created at runtime on access then static, even if they are bound? If so, how can i create a dynamic context menu in XAML? 回答1: This is a

How can you bind to a DynamicResource so you can use a Converter or StringFormat, etc.? (Revision 4)

被刻印的时光 ゝ 提交于 2019-12-17 07:15:16
问题 Note: This is a revision of an earlier design that had the limitation of not being usable in a style, negating its effectiveness quite a bit. However, this new version now works with styles , essentially letting you use it anywhere you can use a binding or a dynamic resource and get the expected results, making it immensely more useful. Technically, this isn't a question. It's a post showing a way I found to easily use converters with a DynamicResource as the source, but in order to follow s

How can you bind to a DynamicResource so you can use a Converter or StringFormat, etc.? (Revision 4)

笑着哭i 提交于 2019-12-17 07:15:08
问题 Note: This is a revision of an earlier design that had the limitation of not being usable in a style, negating its effectiveness quite a bit. However, this new version now works with styles , essentially letting you use it anywhere you can use a binding or a dynamic resource and get the expected results, making it immensely more useful. Technically, this isn't a question. It's a post showing a way I found to easily use converters with a DynamicResource as the source, but in order to follow s