컨트롤은 정의된 스타일을 사용하지 않지만 다른 컨트롤은

엑사666군

XAML의 스타일에 문제가 있습니다. 도움이 될 수 있습니다.

ResourceDictionary "controldefaultstyle"을 만들었습니다.

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="{x:Type Control}" x:Key="ControlDefaultStyle" >
    <Style.Setters>
        <Setter Property="FontFamily" Value="{Binding Path=FontFamily, Source={x:Static Application.Current}, UpdateSourceTrigger=PropertyChanged}"/>
        <Setter Property="FontSize" Value="{Binding Path=FontSize, Source={x:Static Application.Current}, UpdateSourceTrigger=PropertyChanged}"/>
        <Setter Property="Background" Value="{StaticResource SystemBackground}"/>
        <Setter Property="Foreground" Value="{StaticResource SystemForeground}"/>
    </Style.Setters>
</Style>

버튼과 controldefaultstyle을 기반으로 하는 두 개의 다른 ResourceDictionaries를 만든 것보다:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:ext="clr-namespace:StyleResourceDictionariesDemo.ResourceDictionaries.Classes">
<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="ControlDefaultStyle.xaml"/>
</ResourceDictionary.MergedDictionaries>
<Style TargetType="{x:Type Button}" x:Key="ButtonStyle" >
    <Style.BasedOn>
        <ext:MergedStyles BasedOn="{StaticResource {x:Type Button}}" MergeStyle="{StaticResource ControlDefaultStyle}"/>
    </Style.BasedOn>
    <Style.Setters>
        <Setter Property="Width" Value="100"/>
        <Setter Property="Height" Value="30"/>
        <Setter Property="HorizontalContentAlignment" Value="Center"/>
        <Setter Property="VerticalContentAlignment" Value="Top"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}" >
                    <Grid Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" ClipToBounds="True">
                        <Rectangle x:Name="buttonFrame" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
                               Stroke="{TemplateBinding Background}" RadiusX="5" RadiusY="5" StrokeThickness="1" Fill="Transparent"/>
                        <Rectangle x:Name="buttonBody" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                               Stroke="Transparent" RadiusX="5" RadiusY="5" StrokeThickness="1" Fill="{TemplateBinding Background}"/>
                        <TextBlock x:Name="buttonText" HorizontalAlignment="Center" VerticalAlignment="Center" Text="{TemplateBinding Content}" 
                                   Foreground="{TemplateBinding Foreground}"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style.Setters>
    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="Background" Value="{StaticResource IsMouseOverBackground}"/>
            <Setter Property="Foreground" Value="{StaticResource IsMouseOverForeground}"/>
        </Trigger>
        <Trigger Property="IsPressed" Value="True">
            <Setter Property="Background" Value="{StaticResource IsPressedBackground}"/>
            <Setter Property="Foreground" Value="{StaticResource IsPressedForeground}"/>
        </Trigger>
    </Style.Triggers>
</Style>

Textblock과 ControlDefaultStyle을 사용하는 또 다른 것:

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="ControlDefaultStyle.xaml"/>
</ResourceDictionary.MergedDictionaries>
<Style TargetType="{x:Type TextBlock}" x:Key="TextBlockStyle"  >
    <Style.BasedOn>
        <classes:MergedStyles BasedOn="{StaticResource {x:Type TextBlock}}" MergeStyle="{StaticResource ControlDefaultStyle}"/>
    </Style.BasedOn>

    <Style.Setters>
        <Setter Property="Width" Value="200"/>
        <Setter Property="Height" Value="150"/>
        <Setter Property="TextAlignment" Value="Center"/>
        <Setter Property="HorizontalAlignment" Value="Center"/>
        <Setter Property="VerticalAlignment" Value="Top"/>
        <!--<Setter Property="Background" Value="{StaticResource TextBlockBackground}"/>-->
        <!--<Setter Property="Foreground" Value="{StaticResource TextBlockForeground}"/>-->
    </Style.Setters>
</Style>

버튼에서 버튼 스타일을 사용할 때 모든 것이 예상대로 작동하고 색상이 원하는 대로 변경되지만 텍스트 블록은 배경을 변경하지 않으며 이유를 알 수 없습니다. 텍스트 블록과 버튼은 동일하게 보여야 합니다(배경 및 전경의 경우).

어떤 결론?

친절한 미르코

편집: 왼쪽은 맞고 오른쪽 배경은 흰색이 아니라 파란색이어야 합니다.

글꼴 패밀리(콤보박스) 및 크기(슬라이더 제어) 변경은 버튼과 텍스트 블록 모두에서 작동합니다.

여기에 이미지 설명 입력여기에 이미지 설명 입력

앤디

TextBlock은 컨트롤에서 상속되지 않습니다.

상속 체인을 살펴보십시오.

https://docs.microsoft.com/en-us/dotnet/api/system.windows.controls.textblock?view=netframework-4.8

Object DispatcherObject DependencyObject Visual UIElement FrameworkElement TextBlock

이것이 기본 스타일 타겟팅 컨트롤이 텍스트 블록에 적용되지 않는 이유입니다.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

WPF 사용자 지정 컨트롤은 기본 스타일의 ToggleButton을 사용하지 않습니다.

사용자 정의 UI5 컨트롤은 바인딩된 값을 업데이트하지 않습니다.

상속 된 WPF 사용자 지정 컨트롤은 부모 명령을 상속하지 않습니다.

FormGroup에서 비활성화 된 컨트롤 (양식 사용자 지정 양식 컨트롤의 일부)은 부모의 .getRawValue ()에 의해 제외됩니다.

사용자 지정 컨트롤 바인딩은 모델을 업데이트하지 않습니다.

다른 뷰 컨트롤러에서 변수에 액세스 / 전달하는 방법은 무엇입니까? 다음 뷰 컨트롤러는 아니지만 Swift에서 다음 뷰 컨트롤러 이후의 뷰 컨트롤러입니다.

밑줄은 컨트롤의 속성 이름을 허용하지 않습니다.

이미지 컨트롤은 다른 컨트롤과 다르게 변형을 사용합니까?

한 컨트롤러에서 다른 컨트롤러에서 사용할 서비스로 설정된 값은 angular js (new to angular)를 사용하여 페이지 새로 고침시 값을 반환하지 않습니다.

FindDragTarget은 비활성화 된 컨트롤을 감지하지 않습니다.

TypeError : 정의되지 않은 '컨트롤'속성을 읽을 수 없습니다.

Angular : 정의되지 않은 속성 '컨트롤'을 읽을 수 없습니다.

정의되지 않은 AngularJS 컨트롤러를 찾을 수 없습니다.

React : 같은 컨트롤의 다른 인스턴스 만들기

UWP에서 GetRectFromCharacterIndex는 컨트롤의 스타일에 맞게 조정 된 값을 반환하지 않습니다.

컨트롤러의 정의되지 않은 인덱스 (CakePhp)

Mapbox GL 사용자 정의 컨트롤은 사용자 정의 스타일을 적용합니다.

function()을 사용할 때 정의되지 않은 속성 '컨트롤'을 읽을 수 없습니다.

다른 기능 선택 컨트롤에서 작업을 반환하는 사용자 지정 컨트롤

컨트롤의 코드에서 XAML 컨트롤 속성 값을 업데이트하지만 바인딩은 유지합니다.

다른 사용자 양식 컨트롤이 정리 될 때 특정 텍스트 상자를 정리하지 않는 방법은 무엇입니까?

레일은 컨트롤러를 파괴하지 않습니다

Generic.xml에서 다른 사용자 지정 컨트롤을 사용하는 사용자 지정 컨트롤을 만들 수 있습니까?

사용자 지정 컨트롤은 Designer 클래스의 실제 형식이 아닌 일반 "UserControl"이됩니다.

미리 정의 된 가시성, 컨트롤 이름, 기본값으로 Orbeon 사용자 지정 컨트롤 XBL을 만드는 방법은 무엇입니까?

Xamarin.iOS 사용자 지정 컨트롤은 높이 제약 조건을 따르지 않습니다.

동적으로 추가 된 컨트롤의 값은 포스트 백시 유지되지 않습니다.

Laravel의 다른 컨트롤러에서 컨트롤러에 액세스하는 방법은 무엇입니까?

다른 컨트롤의 맨 아래에 컨트롤을 배치하는 방법은 무엇입니까?

TOP 리스트

  1. 1

    C # 16 진수 값 0x12는 잘못된 문자입니다.

  2. 2

    Matlab의 반복 Sortino 비율

  3. 3

    Python의 csv 파일에서 첫 번째 열 삭제

  4. 4

    개체 참조가 개체의 인스턴스로 설정되지 않았습니까? (예외 오류 ~ ASP.NET MVC)

  5. 5

    atob은 인코딩 된 base64 문자열을 디코딩하지 않습니다.

  6. 6

    EventEmitter <string>의 컨텍스트 'this'가 Observable <string> 유형의 'this'메서드에 할당되지 않았습니다.

  7. 7

    병합 셀을 사용하여 워크 시트의 데이터 필터링

  8. 8

    PhpStorm 중단 점에서 변수 값을 볼 수 없습니다.

  9. 9

    jQuery에서 이벤트 핸들러를 제거하는 가장 좋은 방법은 무엇입니까?

  10. 10

    `@ Transactional`이 있음에도 불구하고 이러한 데이터베이스 수정 사항이 롤백되지 않는 이유는 무엇입니까?

  11. 11

    ssh를 사용하여 원격에서 로컬로 파일 복사

  12. 12

    종속 사용자 정의 Lightning 선택 목록 Level2 및 Level3을 설정한 다음 Lightning 구성 요소에서 Level2를 재설정하지만 Level2 캐시 데이터가 저장됨

  13. 13

    2 개의 이미지를 단일 평면 이미지로 결합

  14. 14

    팝업처럼 위젯을 표시하는 방법

  15. 15

    [해결] 쿠키 설정 SameSite = Chrome / JSP, JAVASCRIPT에서 작동하지 않습니다.

  16. 16

    버튼 클릭을 기반으로 특정 CSS 클래스를 추가하는 방법은 무엇입니까?

  17. 17

    React 구성 요소가 자동으로 초기 상태로 다시 렌더링됩니다.

  18. 18

    연결된 서버 쿼리는 작동하지만 동일한 OPENQUERY는 "sys.servers에서 서버 'SERVER'를 찾을 수 없습니다.

  19. 19

    파일 2의 파일 1에서 동일한 줄을 조건으로 바꿉니다.

  20. 20

    아이디어 Intellij : 종속성 org.json : json : 20180813을 찾을 수 없음, maven에서 org.json 라이브러리를 가져올 수 없음

  21. 21

    상황에 맞는 메뉴 색상

뜨겁다태그

보관