मैं WPF टूलकिट के माइक्रोसॉफ्ट के चार्ट नियंत्रण के लिए इस्तेमाल किया अपने ही चार्ट नियंत्रण लिखने के लिए के गुणों को नेस्टेड ViewModels बाध्य कर सकते हैं। मैंने इसके बारे में ब्लॉग किया here। मेरा चार्ट नियंत्रण एक दूसरे के शीर्ष पर चार्ट में याक्स को ढेर करता है। जैसा कि आप लेख में पढ़ सकते हैं यह सब काफी अच्छी तरह से काम करता है। अब मैं एक व्यूमोडेल बनाना चाहता हूं जो चार्ट में डेटा और अक्ष को नियंत्रित करता है। अब तक मैं चार्ट में अक्ष जोड़ने और चार्ट में उन्हें दिखाने में सक्षम हूं। लेकिन जब मुझे लाइनरी जोड़ने की कोशिश की जाती है तो मुझे एक समस्या है क्योंकि इसमें एक निर्भर एक्सिस और एक परस्पर निर्भर एक्सिस संपत्ति है। मुझे नहीं पता कि उचित xAxis और yAxis नियंत्रण को कैसे असाइन किया जाए।
नीचे आप LineSeriesViewModel का हिस्सा देखते हैं। इसमें एक नेस्टेड XAxisViewModel और YAxisViewModel प्रॉपर्टी है।कैसे मैं एक नियंत्रण
public class LineSeriesViewModel : ViewModelBase, IChartComponent
{
XAxisViewModel _xAxis;
public XAxisViewModel XAxis
{
get { return _xAxis; }
set
{
_xAxis = value;
RaisePropertyChanged(() => XAxis);
}
}
//The YAxis Property look the same
}
ViewModels सब अपने स्वयं के DataTemplate है। XAML कोड इस तरह दिखता है:
<UserControl.Resources>
<DataTemplate x:Key="xAxisTemplate" DataType="{x:Type l:YAxisViewModel}">
<chart:LinearAxis x:Name="yAxis" Orientation="Y" Location="Left" Minimum="0" Maximum="10" IsHitTestVisible="False" Width="50" />
</DataTemplate>
<DataTemplate x:Key="yAxisTemplate" DataType="{x:Type l:XAxisViewModel}">
<chart:LinearAxis x:Name="xAxis" Orientation="X" Location="Bottom" Minimum="0" Maximum="100" IsHitTestVisible="False" Height="50" />
</DataTemplate>
<DataTemplate DataType="{x:Type l:LineSeriesViewModel}">
<!--Binding doesn't work on the Dependent and IndependentAxis! -->
<!--YAxis XAxis and Series are properties of the LineSeriesViewModel -->
<l:FastLineSeries DependentAxis="{Binding Path=YAxis}"
IndependentAxis="{Binding Path=XAxis}"
ItemsSource="{Binding Path=Series}"/>
</DataTemplate>
<Style TargetType="ItemsControl">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<!--My stacked chart control -->
<l:StackedPanel x:Name="stackedPanel" Width="Auto" Height="Auto" Background="LightBlue">
</l:StackedPanel>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ClipToBounds="True">
<!-- View is an ObservableCollection of all axes and series-->
<ItemsControl x:Name="chartItems" ItemsSource="{Binding Path=View}" Focusable="False">
</ItemsControl>
</Grid>
इस कोड को बहुत अच्छी तरह से काम करता है। जब मैं अक्ष जोड़ता हूं तो वे खींचे जाते हैं। लेकिन निर्भरांक एक्सिस और इनडिपेन्टेंट एक्सिस लाइनों के नियंत्रण में शून्य रहती है, इसलिए श्रृंखला तैयार नहीं होती है। मैं नेस्टेड व्यूमोडल्स को नियंत्रण के गुणों में कैसे बांध सकता हूं?