액세스) 또는 심지어 응용 프로그램. StaticResource 바인딩 표현식은 요소 트리를 걸어 다니는 방법을 알고 있거나 요소 자체가하는 것처럼 보입니다. 프로그래밍 방식으로 똑같은 일을하고 싶습니다 :는, 프로그램 내가 프로그래밍 방식으로 내가 XAML에서와 같이 많은 정적 리소스에 액세스하고 싶은 실버 정적 자원
<UserControl x:Class="MyCustomControl" ...>
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources.xaml"/> <!-- Sets 'My.Text.Key' to System.String 'Hello, World!' -->
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
</UserControl>
public partial class MyCustomControl
{
public MyCustomControl()
{
InitializeComponent();
string myCustomValue = this.Resources[MyCustomValue] as string; // myCustomValue becomes null!
}
}
심지어이 간단한 테스트에서 내 리소스는 프로그래밍 방식으로 액세스 할 수없는 것 같습니다. 그리고 이것은 내가 실제로하려고했던 단순화 된 버전입니다 : 사용자 정의 동적 속성이 첨부 된 요소 (예 : uiElement.Resources [key])를 통해 정적 리소스를 찾습니다.
"점"을 내 키 (예 : "MyTestKey"대신 "MyTestKey")로 가져 가면 프로그래밍 방식으로 리소스를 볼 수 있습니다 .XAML 또는 코드에서 리소스 이름 지정에 대한 규칙이 있습니까? -behind? – Trinition