2011-10-13 23 views
5

मैं वास्तव में WPF कस्टम कंट्रोल लाइब्रेरी से अन्य फ़ाइल से WPF स्टाइल लोड करने का प्रयास कर रहा हूं लेकिन मैं यहां लोड करने में विफल रहा हूं मेरा समाधान है।संसाधन फ़ाइल से WPF स्टाइल लोड हो रहा है

समाधान दो परियोजनाओं

प्रकार WPF कस्टम नियंत्रण पुस्तकालय

  • प्रकार के WpfTestApp WPF आवेदन लाइब्रेरी के

    1. WpfTestControls जो WpfTestControls के संदर्भ में है शामिल

    MainWindow.xaml डब्ल्यूपीएफ एप्लीकेशन लाइब्रेरी से

    <Window.Resources> 
        <Style x:Key="TempStyle" TargetType="{x:Type TextBox}"> 
         <Setter Property="BorderBrush" Value="Green"/> 
        </Style> 
    </Window.Resources> 
    <Grid> 
        <TextBox Height="50px" Width="100px" Style="{DynamicResource TempStyle}"/> 
    </Grid> 
    

    Generic.xaml WPF से कस्टम नियंत्रण पुस्तकालय

    <ResourceDictionary 
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
    <ResourceDictionary.MergedDictionaries> 
        <ResourceDictionary Source="/WpfTestControls;component/TextBoxStyle.xaml"/> 
    </ResourceDictionary.MergedDictionaries> 
    

    TextBoxStyle.xaml WPF से कस्टम नियंत्रण पुस्तकालय

    <ResourceDictionary 
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
    <Style x:Key="TempStyle" TargetType="{x:Type TextBox}"> 
        <Setter Property="BorderBrush" Value="Green"/> 
    </Style> 
    

    मेरे AssemblyInfo.cs फ़ाइल निम्नलिखित

    [assembly: ThemeInfo(
    ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 
    //(used if a resource is not found in the page, 
    // or application resource dictionaries) 
    ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 
    //(used if a resource is not found in the page, 
    // app, or any theme specific resource dictionaries))] 
    

    शामिल लेकिन फिर भी मैं शैली लोड करने में नाकाम रहने रहा हूँ। तो मैं उपयोग कर रहा हूँ Generic.xaml सब कुछ काम अच्छा उदाहरण के लिए अपेक्षा के अनुरूप

    <Window x:Class="WpfTestApp.MainWindow" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        Title="MainWindow" Height="350" Width="525"> 
    
    <Window.Resources> 
        <Style x:Key="TempStyle" TargetType="{x:Type TextBox}"> 
         <Setter Property="BorderBrush" Value="Green"/> 
        </Style> 
    </Window.Resources> 
    <Grid> 
        <TextBox Height="50px" Width="100px" Style="{StaticResource TempStyle}"/> 
    </Grid> 
    

    क्या मैं गलत कर रहा हूँ निम्नलिखित कोड काम करता है का उपयोग नहीं? अग्रिम

  • उत्तर

    5

    मेरे लिए कुछ बातें उत्तर दें में धन्यवाद ...

    1. "WPF कस्टम नियंत्रण लाइब्रेरी" के रूप में "WpfTestControls" विधानसभा विधानसभा में एक ही है?
    2. यदि नहीं, तो क्या "डब्ल्यूपीएफ कस्टम कंट्रोल लाइब्रेरी" में "WpfTestControls" असेंबली का संदर्भ है?
    3. क्या आपके WpfTestApp में "WPF कस्टम कंट्रोल लाइब्रेरी" और "WpfTestControls" असेंबली दोनों का संदर्भ है?

    यदि आप उस संदर्भ को जोड़ते हैं, तो संसाधनों को सही ढंग से लोड करना चाहिए।

    मेरे चरण ...

    1. एक "WPF कस्टम नियंत्रण पुस्तकालय" जोड़ें कहते हैं कि "ThemesLibray"
    2. इस में "थीम्स" फ़ोल्डर

    के तहत संसाधन दो शब्दकोशों जोड़ने TextBoxStyle.xaml

    <ResourceDictionary 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
        <Style x:Key="GreenTextBoxStyle" TargetType="{x:Type TextBox}"> 
         <Setter Property="Background" Value="Green"/> 
        </Style> 
    </ResourceDictionary> 
    

    जेनेरिक.एक्सएएम

    <ResourceDictionary 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
        <ResourceDictionary.MergedDictionaries> 
         <ResourceDictionary Source="TextBoxStyle.xaml"/> 
        </ResourceDictionary.MergedDictionaries> 
        </ResourceDictionary> 
    
    1. मैं मुख्य starup परियोजना "MyWPFTestApp" ThemesLibray को विधानसभा संदर्भ है कि है। कि विंडो ThemesLibrary संसाधनों इस तरह से मिला दिया गया है ....

      <Window x:Class="MyWPFTestApp.Window7" 
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           Title="Window7" Height="300" Width="300"> 
          <Window.Resources> 
           <ResourceDictionary> 
            <ResourceDictionary.MergedDictionaries> 
             <ResourceDictionary 
              Source="/ThemseLibrary;component/Themes/Generic.xaml"/>  
            </ResourceDictionary.MergedDictionaries>    
           </ResourceDictionary> 
          </Window.Resources> 
          <Grid> 
           <TextBox Style="{StaticResource GreenTextBoxStyle}"/> 
          </Grid> 
      </Window> 
      

    जब मैं MyWPFTestApp लॉन्च करते हैं, मैं हरी पाठ बॉक्स के साथ विंडो देखते हैं।

    +0

    हाय हो सकता है कि मैंने इसे गलत लिखा लेकिन समाधान में केवल दो परियोजनाएं हैं जो टाइप डब्लूपीएफ कस्टम कंट्रोल लाइब्रेरी के WpfTestControls, और टाइप Wpf एप्लिकेशन के WpfTestApp में दो WpfTestControls संदर्भित हैं। – Robob

    +0

    ठीक है तो मेरा संपादन ऊपर देखें ... –

    +0

    आप सही हैं लेकिन जैसा कि मुझे लगता है कि यह पिछले समाधान के साथ काम करना चाहिए। यह कामकाज है जिसे मैं अभी अपनाना चाहता हूं – Robob

    1

    मुख्य बात यह है कि: सुनिश्चित करें कि आपके पास संसाधन के लिए सेट संसाधन संसाधन का निर्माण कार्य है।

    संबंधित मुद्दे