문제

"MySilverLightControls"라는 Silverlight Controls 어셈블리가 있습니다. 해당 어셈블리로 여러 폴더를 아래로 내려갑니다. 제 3 자 공급 업체의 그리드 열을 연장하는 클래스가 있습니다.

또한 자원 사전을 만들었습니다 Generic.xaml, 이것은 위치에 있습니다 Themes 어셈블리 폴더. 그 리소스 사전에서 나는 myimagecolumntemplate:

<ControlTemplate x:Name="MyImageColumnTemplate" >
    <Grid Margin="8,8,4,4" MaxHeight="32" MaxWidth="32">
        <Grid.Resources>
            <localGrid:StatusColumnImageConverter x:Key="ImageContentConverter"/>
        </Grid.Resources>
        <Border Margin="5,5,0,0" Background="Black" Opacity="0.15" CornerRadius="5" />
        <Border Background="#FF6E6E6E" CornerRadius="4,4,4,4" Padding="4" Margin="0,0,5,5">
            <Border Background="White" CornerRadius="2,2,2,2" Padding="3">
                <Image Source="{Binding EditValue, Converter={StaticResource ImageContentConverter}}" Stretch="Uniform"/>
            </Border>
        </Border>
    </Grid>
</ControlTemplate>

내 질문은 : MyimageColumn 에서이 제어 템플릿을 프로그래밍 방식으로 참조/로드하여 열의 속성에 할당 할 수있는 방법은 무엇입니까? 나는 이것과 유사한 구문을 사용할 것으로 기대합니다.

ControlTemplate ct = (ControlTemplate)Application.Current.Resources["MyImageColumnTemplate"];

그러나 이것은 항상 null을 반환합니다. 어셈블리를 반사기에로드하면 Generic.xaml 파일이 있습니다. 자원의 이름은 MySilverlightControls.g.resources, 그리고 그 안에있는 길은입니다 themes/generic.xaml.

이 리소스 사전에서 개별 항목에 정확히 어떻게 갈 수 있습니까?

도움이 되었습니까?

해결책

해결되었습니다.

나는 필요했다 :

  • 내 리소스 사전을로드하십시오
  • 응용 프로그램의 리소스와 병합하십시오
  • 응용 프로그램 리소스에서 제어 템플릿을로드하십시오

자원 사전로드의 일환으로 나는 또한 등록해야했습니다. pack URI 계획. 그런 다음 XAML의 약간의 오류로 인해 미친 COM 기반 예외를 처리해야했습니다. 또한 XAML을 별도의 리소스 사전 파일로 옮겨야했습니다. generic.xaml을 통해이를 수행하려고 노력했습니다 (XAML은 결함이없고 새로 생성 된 리소스 사전 파일을 사용하여 잘로드 할 수 있음). 따라서 단순화하면 코드였습니다.

if (!UriParser.IsKnownScheme("pack"))
    UriParser.Register(new GenericUriParser(GenericUriParserOptions.GenericAuthority), "pack", -1);

ResourceDictionary dict = new ResourceDictionary();
Uri uri = new Uri("/MySilverlightControls;component/themes/Dictionary1.xaml", UriKind.Relative);
dict.Source = uri;
Application.Current.Resources.MergedDictionaries.Add(dict);
ControlTemplate ct = (ControlTemplate)Application.Current.Resources["MyImageColumnTemplate"];

이 솔루션에 대한 자세한 내용을 이 블로그 게시물.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top