如何在silverlight中将折线图与组合框绑定?
我在 silverlgiht 应用程序的图表中使用 2 个不同的线系列
<toolkit:Chart Grid.Column="1" Grid.Row="2" Height="300" Width="450" HorizontalAlignment="Left" Name="FarmCondtion" Title="Farm Condition" VerticalAlignment="Top" >
<toolkit:LineSeries x:Name="TempLine" Visibility="Visible" Title="Temprature" IndependentValueBinding="{Binding Date}"
DependentValueBinding="{Binding Temp}" ItemsSource="{Binding }"/>
<toolkit:LineSeries x:Name="MoistureLine" Visibility="Collapsed" Title="Moisture" IndependentValueBinding="{Binding Date}"
DependentValueBinding="{Binding Moist}" ItemsSource="{Binding }"/>
</toolkit:Chart>
,并且使用组合框:
<ComboBox x:Name="FarmCombo" SelectionChanged="FarmCombo_SelectionChanged">
<ComboBox.Items >
<ComboBoxItem Content="Temprature"></ComboBoxItem>
<ComboBoxItem Content="Moisture"></ComboBoxItem>
</ComboBox.Items>
</ComboBox>
我想创建一个事件 FarmCombo_SelectionChanged
,其中我只想显示在组合框。
我将此事件用作:
private void FarmCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
string selectedItem = FarmCombo.Items[FarmCombo.SelectedIndex].ToString();
if (selectedItem == "Temprature")
{
TempLine.Visibility.Equals("Visible");
MoistureLine.Visibility.Equals("Collapsed");
}
else if (selectedItem == "Moisture")
{
MoistureLine.Visibility.Equals("Visible");
TempLine.Visibility.Equals("Collapsed");
}
}
但代码对线系列的可见性没有任何影响。
请建议我如何使用组合框选择要在图表中显示的线系列?
谢谢
I am using 2 different line series in chart in silverlgiht application
<toolkit:Chart Grid.Column="1" Grid.Row="2" Height="300" Width="450" HorizontalAlignment="Left" Name="FarmCondtion" Title="Farm Condition" VerticalAlignment="Top" >
<toolkit:LineSeries x:Name="TempLine" Visibility="Visible" Title="Temprature" IndependentValueBinding="{Binding Date}"
DependentValueBinding="{Binding Temp}" ItemsSource="{Binding }"/>
<toolkit:LineSeries x:Name="MoistureLine" Visibility="Collapsed" Title="Moisture" IndependentValueBinding="{Binding Date}"
DependentValueBinding="{Binding Moist}" ItemsSource="{Binding }"/>
</toolkit:Chart>
and i am using a combo box :
<ComboBox x:Name="FarmCombo" SelectionChanged="FarmCombo_SelectionChanged">
<ComboBox.Items >
<ComboBoxItem Content="Temprature"></ComboBoxItem>
<ComboBoxItem Content="Moisture"></ComboBoxItem>
</ComboBox.Items>
</ComboBox>
I want to create an event FarmCombo_SelectionChanged
in which i want to show only the chart's line serie which is seleted in the combo box.
I used this event as :
private void FarmCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
string selectedItem = FarmCombo.Items[FarmCombo.SelectedIndex].ToString();
if (selectedItem == "Temprature")
{
TempLine.Visibility.Equals("Visible");
MoistureLine.Visibility.Equals("Collapsed");
}
else if (selectedItem == "Moisture")
{
MoistureLine.Visibility.Equals("Visible");
TempLine.Visibility.Equals("Collapsed");
}
}
But the code doesn't have any effect on the visibility of Line Series.
Please suggest How can i use the Combo Box to choose which Line Series to be shown in the chart ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 SelectionChanged 事件的代码中,您实际上从未设置线系列的可见性。
MoistureLine.Visibility.Equals("Visible");
所做的只是返回一个布尔值,指示可见性是否可见,它实际上并没有设置该属性。此外,
SelectionChangedEventArgs
包含已选择的值,因此您无需引用组合框本身即可获取此信息。以下代码应该更符合您正在寻找的内容:
In your code for the SelectionChanged event you never actually set the Visibility of the line series. All
MoistureLine.Visibility.Equals("Visible");
does is return a boolean value indicating whether the Visiblity is Visible, it doesn't actually set the property.Additionally the
SelectionChangedEventArgs
contain the value that has been selected so you don't need to reference the combobox itself to get this information.The following code should more aligned with what you're looking for: