سؤال

ولدي هذه المكتبة مع العرف <م> اللون خصائص. أريد أن أكون قادرا على استخدام هذه الخصائص في XAML مثل هذا:

    <Style TargetType="{x:Type eg:MyWindow}">
        <Setter Property="Background">
            <Setter.Value>
                <SolidColorBrush Color="CustomClass.CustomColorProperty"/>
            </Setter.Value>
        </Setter>
    </Style>

ومساحة الاسم الذي يحتوي <م> CustomClass المشار إليها بالفعل. كيف ينبغي أن تذهب نحو هذا؟ شكرا.

وتحرير:

ولقد لاحظت أن <م> CustomClass هو ثابت، لذلك لا يمكن إنشاء مثيل في XAML. أيضا، عندما كنت اكتب <م> على سبيل المثال: ، <م> CustomClass لا تظهر في التحسس. لا أستطيع الحصول على أي من الحلول الخاصة بك في العمل، على الرغم من أنها ينبغي، إذا كان لي من الدرجة المثال. هل هناك حلا لهذه الحالة؟

وتحرير 2:

وهذه هي الطبقة الفعلية ومساحة الاسم:

namespace Assergs.Windows
{
    public static class OfficeColors
    {
        public class Background
        {
            public static Color OfficeColor1 = (Color)ColorConverter.ConvertFromString("#e4e6e8");
            public static Color OfficeColor2 = (Color)ColorConverter.ConvertFromString("#dce0ed");
            public static Color OfficeColor3 = (Color)ColorConverter.ConvertFromString("#a8c3e0");
        }
    }
}

وهذه هي مساحة XAML:

xmlns:aw="clr-namespace:Assergs.Windows;assembly=Assergs.Windows"

وإذا كنت تستخدم هذا الخط، كما اقترح Zenuka:

<SolidColorBrush Color="{x:Static aw:OfficeColors.Background.OfficeColor1}"/>

وويلقي هذا الخطأ في وقت الترجمة:

Cannot find the type 'OfficeColors.Background'. Note that type names are case sensitive.
هل كانت مفيدة؟

المحلول

استخدم هذا:

<SolidColorBrush Color="{x:Static aw:OfficeColors+Background.OfficeColor1}"/>

لاحظ + التوقيع بدلا من نقطة مرجع الطبقات المتداخلة

نصائح أخرى

وأنا asuming لديك خاصية ثابتة على CustomClass؟ ثم هل يمكن استخدام:

<SolidColorBrush Color="{x:Static eg:CustomClass.CustomColorProperty}"/>

ولكن ربما كنت بحاجة إلى تغيير بادئة مساحة الاسم ...

وتحرير:
تكمن المشكلة لأنك معلنا فئة في فئة أخرى ... أقترح عليك تحريك الطبقة Backgroud خارج الطبقة OfficeColors وتعلن أنها ثابتة أو تحريك خصائص الطبقة الخلفية للطبقة OfficeColors (ربما مع بادئة الخلفية)، أو النطاقات استخدام كما كنت نوع من المحاولة.

والمتعة:)

وEDIT2:
استخدام أسلوب نير باستخدام علامة + "فصيل عبد الواحد: OfficeColors + Background.OfficeColor1" مرجع الطبقات المتداخلة، لم يكن يعلم أن واحدة:)

وأنت يجب أن يعلن مثيل من فئة واحدة من الموارد. (على افتراض CustomColorProperty ليس ثابت)

<CustomNamespace.CustomClass x:Key=CcInstance />
<Style TargetType="{x:Type eg:MyWindow}">        
     <Setter Property="Background">            
         <Setter.Value>                
              <SolidColorBrush Color="{Binding Source={StaticResource CcInstance}, Path=CustomColorProperty} />            
         </Setter.Value>        
     </Setter>    
</Style>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top