Hi,
I'm trying to figure out how to resolve a dynamic resource without adding an item to the logical or visual tree.
The following sample does not resolve the binding if the Loaded event in the Window is not specified.
<Window x:Class="DynamicResourceTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:DynamicResourceTest"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Title="{DynamicResource string1}" Height="300" Width="300"
Loaded="Window_Loaded">
<Window.Resources>
<Button x:Key="myButton" Content="{DynamicResource string1}"/>
<sys:String x:Key="string1">This is a test!</sys:String>
</Window.Resources>
<Grid>
<TextBlock Text="{Binding Source={StaticResource myButton}, Path=Content}"/>
</Grid>
</Window>
If the "code behind" handler "
Window_Loaded" is specified the binding works.
using System.Windows;
using System.Windows.Controls;
namespace DynamicResourceTest
{
/// <summary>
/// Interaktionslogik für Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Button button = this.FindResource("myButton") as Button;
this.AddLogicalChild(button);
}
}
}
Is there any alternative without specifiying the handler to get the properties resolved?
Regards
Jörg