2011-05-05 7 views
2

제 자신의 프로젝트에서 여러 UserControls에서 사용하려는 스타일을 generic.xaml에 만들었습니다. 같은 방식으로 그래서로드 generic.xaml을 보인다 난 사용자 지정 컨트롤의 스타일을 정의하고이 하나가 작동이 정의 된 스타일 :Howto : generic.xaml에 정의 된 스타일을 UserControl에 적용 하시겠습니까? (WPF)

<Style TargetType="{x:Type UserControl}" x:Key="ServiceStyle" x:Name="ServiceStyle"> 
    <Setter Property="Opacity" Value="0.5"/> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type UserControl}"> 
       <Border Name="border" CornerRadius="20" 
         Margin="10" 
         BorderThickness="5" 
         BorderBrush="Black"> 
         <ContentPresenter Content="{TemplateBinding Content}" 
              Margin="{TemplateBinding Padding}"/> 
       </Border> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

그러나 지금은이 스타일을 사용하고 싶지만 그럴 수 없어 그것을 작동 시키십시오. 나는 다음과 같은 방법으로 UserControl을의 사용자 지정 인스턴스에 스타일의 매개 변수로 추가 tryed했습니다

<UserControl 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="clr-namespace:Netcarity" 
    xmlns:CustomControls="clr-namespace:Netcarity.CustomControls" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" x:Name="Portier_deur" x:Class="Netcarity.UserControlPortier" 
    Height="600" Width="800" MouseDown="UserControl_MouseDown" Loaded="UserControl_Loaded" mc:Ignorable="d" 
    Style="{StaticResource ServiceStyle}"> 

그러나이 나에게 자원 ServiceStyle 찾을 수 없다는 메모를 제공합니다. 실행하려고 할 때 런타임 오류가 있습니다.

미리 감사드립니다.

+0

'WFP'가 아니라 'WPF'를 원한다고 가정하고 태그가 지정되었습니다. –

답변

0

Generic.xaml은 사용자 지정 컨트롤이 아닌 스타일을 저장할 적절한 곳이 아닌 것 같습니다. 어딘가에 generic.xaml 대신 App.xaml에 syle을 넣을 힌트를 찾았고 직접 작업했습니다. 따라서 Generic.xaml은 customControls 스타일을 저장하는 데에만 사용할 수 있습니다. 누군가이 행동에 대해 더 많은 교육을받은 이유를 추가 할 수 있습니까?

0

Generic.xaml이 ComponentResourceKey를 사용하는 경우.

관련 문제