Page 1 of 1

How to Use "Static Resource(.xaml)" file in cshtml5.

Posted: Tue Nov 22, 2016 10:42 pm
by oprakash
I have a .xaml file Namely "Default.resx" Which is in a separate folder called "Resources". I register this file on app.xaml file as below.
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Resources/Default.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>


Then try to use on a .XAML file like
<TextBox x:Name="TxtClient" FontSize="9" Grid.Column="3" vali:TextBoxBehavior.HomeOnLostFocus="True" LostFocus="TxtClient_LostFocus"
Height="19" Style="{StaticResource TextAutoCompleteStyle}" Text="{Binding FieldName, Mode=TwoWay}" Margin="4,1,1,0" d:LayoutOverrides="HorizontalAlignment" />


'TextAutoCompleteStyle " I have defined on Default.resx file as below
<Style x:Key="TextAutoCompleteStyle" TargetType="TextBox">
<Setter Property="Height" Value="15"/>
<Setter Property="Width" Value="10"/>
<Setter Property="Foreground" Value="Black"/>
</Style>

Note- However inline static resource is working fine. If we define the static resource on page and use to the control on the same page.

Please Help
Thanks

Re: How to Use "Static Resource(.xaml)" file in cshtml5.

Posted: Thu Feb 28, 2019 6:19 pm
by fangeles
Hi JS-Support@Userware,

Any workaround for this?
Image

It can't retrieve the resource when the resource is used on e.g. Page, but it is working on child elements.

Error: Cannot find resource named "ResourceKey". Resource names are case sensitive.


Thanks.

Re: How to Use "Static Resource(.xaml)" file in cshtml5.

Posted: Mon Mar 04, 2019 2:11 am
by JS-Support @Userware
Hi,

This is consistent with the Microsoft XAML specifications because the resource referenced by "StaticResource" needs to be defined on one of the parent elements rather than on the element itself.

For example, the following code will raise an exception in WPF because the "TextBlockStyle" is defined on the same element as where it is used:

Code: Select all

        <TextBlock Text="Hello!" Style="{StaticResource TextBlockStyle}">
            <TextBlock.Resources>
                <Style x:Key="TextBlockStyle" TargetType="TextBlock">
                    <Style.Setters>
                        <Setter Property="Foreground" Value="Red"/>
                    </Style.Setters>
                </Style>
            </TextBlock.Resources>
        </TextBlock>


Please find attached a sample WPF solution.

Does your code come from a Silverlight/WPF application?

By the way, a workaround is to put the MergedDictionaries in "App.xaml", because all the resources defined there are accessible from everywhere in your application. You will find an example at:
https://github.com/cshtml5/CSHTML5.Samples.Showcase/blob/master/CSHTML5.Samples.Showcase/App.xaml

Thanks.
Regards