[संपादित करें] * मैं अपवादWPF आयत शैली प्रोग्राम के (MVVM) (Noob) कैसे बदलें
'System.Windows.Style' is not a valid value for property 'Fill'
*
यह मेरी पहली पोस्ट है, मैं पहले से ही है है वापस लौटे शामिल करने के लिए भूल गया था उन प्रश्नों के लिए बहुत सारे खोज किए गए हैं जहां इसका सफलता पहले से ही उत्तर दिया जा सकता है। जब एमवीवीएम, प्रिज्म और डब्ल्यूपीएफ की बात आती है तो मैं पूरी तरह से नोब हूं और मुझे इस पर गहरे छोर में फेंक दिया गया है।
मैं मॉडल (बाध्यकारी उत्तीर्ण) में एक बूलियन के आधार पर 2 आयताकारों की सामग्री को बदलना चाहता हूं।
यदि कोई परीक्षण पास (बूल ट्रू) देता है तो हम पहले आयताकार के लिए रंगीन ग्रीन प्रदर्शित करते हैं, और दूसरा आयताकार UserControl प्रदर्शित करेगा। संसाधन शैली x: Key = "RectanglePass"। तो परीक्षण विफल रहता है, तो पहली आयत लाल है, और दूसरा प्रदर्शित करता है UserControl.Resource शैली एक्स: मुख्य = "RectangleFail"
मैं निम्नलिखित XAML कोड है:
<UserControl x:Class="Integration.Memjet.Aoqc.Views.ProcessResultView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.Resources>
<Style x:Key="RectangleFail" TargetType="Rectangle">
<Setter Property="Fill">
<Setter.Value>
<VisualBrush>
....
</VisualBrush>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="RectanglePass" TargetType="Rectangle">
<Setter Property="Fill">
<Setter.Value>
<VisualBrush>
....
</VisualBrush>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="60"></RowDefinition>
<RowDefinition Height="60"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Label VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="20">PASS</Label>
<Rectangle Name="rectStatus" Grid.Row="1">
<Rectangle.Style>
<Style TargetType="{x:Type Rectangle}">
<Style.Triggers>
<DataTrigger Binding="{Binding Passed}" Value="True">
<Setter Property="Fill" Value="Green" />
</DataTrigger>
<DataTrigger Binding="{Binding Passed}" Value="False">
<Setter Property="Fill" Value="Red" />
</DataTrigger>
</Style.Triggers>
</Style>
</Rectangle.Style>
</Rectangle>
<Rectangle Name="rectStatusImg" Width="120" Height="120" Grid.Row="2" >
<Rectangle.Style>
<Style TargetType="{x:Type Rectangle}">
<Style.Triggers>
<DataTrigger Binding="{Binding Passed}" Value="True">
<Setter Property="Fill" Value="{StaticResource RectanglePass}" />
</DataTrigger>
<DataTrigger Binding="{Binding Passed}" Value="False">
<Setter Property="Fill" Value="{StaticResource RectangleFail}" />
</DataTrigger>
</Style.Triggers>
</Style>
</Rectangle.Style>
</Rectangle>
</Grid>
</UserControl>
से काम नहीं होता और एक अपवाद देता है। यदि मैं इस पंक्ति के साथ दूसरे आयत टैग (rectStatusImg) को प्रतिस्थापित करना था;
<Rectangle Name="rectStatusImg" Style="{StaticResource RectanglePass}" Width="120" Height="120" Grid.Row="2" ></Rectangle>
xaml काम करता है और अपेक्षित परिणाम उत्पन्न करता है! लेकिन मैं इसे बुलियन पास करने के लिए बाध्य करना चाहता हूं ताकि मैं इसे प्रोग्रामेटिक रूप से बदल सकूं।
मुझे उम्मीद है कि मैं यहां अपनी समस्या को समझाने में सक्षम था।
आपकी मदद के लिए धन्यवाद, यह साइट हमेशा एक खजाना और एक बड़ी मदद रही है।
चीयर्स, साइमन
क्या आप कहीं भी UserControl का DataContext सेट कर रहे हैं? ऐसा लगता है कि बाध्यकारी समेत चीजें ठीक से स्थापित की गई हैं, लेकिन यह स्पष्ट नहीं है कि क्या आप वास्तव में डेटाकेंटेक्स्ट सेट अप करते हैं ताकि सिस्टम को दिखाया जा सके जहां मूल्य वास्तव में आ रहे हैं। – Tim
हाय @ टिम, fileView.xaml.cs में इसकी एक फ़ाइल व्यूमोडेल प्रॉपर्टी है जो DataContext को FileViewMode के रूप में लौटाती है। ग्रिड में DataContext जोड़कर यह दिलचस्प है। यह एक अपवाद पैदा करना बंद कर दिया। – sayo9394