如何在silverlight中将折线图与组合框绑定?

发布于 2025-01-07 05:20:37 字数 1874 浏览 0 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时常饿 2025-01-14 05:20:37

在 SelectionChanged 事件的代码中,您实际上从未设置线系列的可见性。 MoistureLine.Visibility.Equals("Visible"); 所做的只是返回一个布尔值,指示可见性是否可见,它实际上并没有设置该属性。

此外,SelectionChangedEventArgs 包含已选择的值,因此您无需引用组合框本身即可获取此信息。

以下代码应该更符合您正在寻找的内容:

private void FarmCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
{          
       if(e.AddedItems.Count == 1)
       {
            string selectedItem = e.AddedItems[0].ToString();

            if (selectedItem == "Temprature")
            {
                TempLine.Visibility = Visibility.Visible;
                MoistureLine.Visibility = Visibility.Collapsed;
            }
            else if (selectedItem  == "Moisture")
            {
                MoistureLine.Visibility = Visibility.Visible;
                TempLine.Visibility = Visibility.Collapsed;
            }
        }
}

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:

private void FarmCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
{          
       if(e.AddedItems.Count == 1)
       {
            string selectedItem = e.AddedItems[0].ToString();

            if (selectedItem == "Temprature")
            {
                TempLine.Visibility = Visibility.Visible;
                MoistureLine.Visibility = Visibility.Collapsed;
            }
            else if (selectedItem  == "Moisture")
            {
                MoistureLine.Visibility = Visibility.Visible;
                TempLine.Visibility = Visibility.Collapsed;
            }
        }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文