سؤال

كنت أرغب في تغيير اللون الأمامي عندما اخترت listboxitem وفعلت ذلك باستخدام هذا الجزء من الكود:

<DataTrigger Binding="{Binding  
RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBoxItem}},Path=IsSelected}" Value="True">
                            <Setter TargetName="descriptionTB" Property="Foreground" Value="#000"/>
</DataTrigger>

يمكنك العثور على الجواب هنا.

ولكن إذا كنت أرغب في القيام بذلك يمزج, ، كيف يمكن أن يفعل ذلك دون الحفر في xaml؟

شكرًا لك

هل كانت مفيدة؟

المحلول

أرتور ،

يسمح مصمم المشغلات في مزيج التعبير فقط بإضافة وتعديل EventTriggers ومشغلات الممتلكات. لم أجد طريقة لإضافة datatriggers مع مزيج. لست متأكدًا أيضًا من كيفية تعيين RisoorderSource ملزمة باستخدام مزيج أيضًا. لقد قمت دائمًا بتسليم الكود XAML للاختبار واستخدام مزيج لكل شيء آخر.

نصائح أخرى

Maybe I'm misunderstanding the question but can't you just create a style resource for descriptionTB and let the designer only deal with that style definition and not the binding?

<DataTrigger Binding="..">
    <Setter TargetName="descriptionTB" Property="Style" Value="{StaticResource DescriptionTextBoxStyle}" />
</DataTrigger>

In the resources section of your control or window you add the style definition:

<Style TargetType="{x:Type TextBox}" x:Key="DescriptionTextBoxStyle">
    <Setter Property="Foreground" Value="#000" />
</Style>

If you want to further isolate the designer from the mechanics of the UI you can create a resource dictionary in a separate xaml file in which you can collect all styles meant for the designer. Then you can merge that resource dictionary with your control's or application's main resources.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top