silverlight   发布时间:2022-05-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Silverlight的空间Combobox的初步使用)大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

开始很简单的学了xmal代码如下:但是报错,不知道为什么? <ComboBox HorizontalAlignment="left" VerticalAlignment="bottom" x:Name="abc" SELEctionChanged="abc_SELEctionChanged"> <ComboBoxItem Content="1" IsSELEcted="T
@H_944_6@
@H_944_6@

开始很简单的学了xmal代码如下:但是报错,不知道为什么?

<ComboBox HorizontalAlignment="Left"  VerticalAlignment="Bottom" x:Name="abc" SELEctionChanged="abc_SELEctionChanged">
            <ComboBoxItem Content="1" IsSELEcted="True" />
            <ComboBoxItem Content="2" />
            <ComboBoxItem Content="3"  />
        </ComboBox>
代码获取值是报错的:
ComboBoxItem item = abc.SELEctedItem as ComboBoxItem;
            txt.Text = item.Content.ToString();

修改代码:不需要 IsSELEcted="True"也不需要 Itemssource="{Binding}"才可以运行,但是我又想启动选择第二项。。。怎么办

然后再cs代码中通过abc.SELEctedIndex = 2;才有用,哎......

下面看看整个代码吧,很乱,一个是xmal初始内容数据,一个是绑定列表对象:

xmal如下:

<Grid x:Name="LayoutRoot" BACkground="White" Height="228" Width="378">
        <ComboBox x:Name="cbbTest" Height="30" Width="100" Itemssource="{Binding}" DisplaymemberPath="Id" SELEctionChanged="SELEct"/>
        <TextBlock Height="30" Width="100" HorizontalAlignment="Center" VerticalAlignment="Bottom" x:Name="txt"></TextBlock>
        <ComboBox HorizontalAlignment="Left"   VerticalAlignment="Bottom" x:Name="abc" SELEctionChanged="abc_SELEctionChanged">
            <ComboBoxItem Content="1"  />
            <ComboBoxItem Content="2" />
            <ComboBoxItem Content="3"  />
        </ComboBox>
    </Grid>

cs.如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace CombomBox
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            getData();
            abc.SELEctedIndex = 2;
        }
        List<Class1> lstsource = new List<Class1>();
        private void getData() {
            lstsource.Add(new Class1 { Id="1",Name="Oracle"});
            lstsource.Add(new Class1 { Id = "2",Name = "java" });
            lstsource.Add(new Class1 { Id = "3",Name = "linux" });
            lstsource.Add(new Class1 { Id = "4",Name = "windows 8" });
            cbbTest.Itemssource = lstsource;
            cbbTest.SELEctedIndex = 0;
        }

        private void SELEct(object sender,SELEctionChangedEventArgs E)
        {
            String SELEctedId = (cbbTest.SELEctedItem as Class1).Name;
            txt.Text = SELEctedId;
        }
        private void abc_SELEctionChanged(object sender,SELEctionChangedEventArgs E)
        {
            ComboBoxItem item = abc.SELEctedItem as ComboBoxItem;
            txt.Text = item.Content.ToString();
        }
    }
}

数据类如下:

namespace CombomBox
{
    public class Class1
    {
        public String Name { get ;set;}
        public String Id { get; set; }
    }
}
最后给出效果吧:

Silverlight的空间Combobox的初步使用)

Silverlight的空间Combobox的初步使用)

大佬总结

以上是大佬教程为你收集整理的Silverlight的空间Combobox的初步使用)全部内容,希望文章能够帮你解决Silverlight的空间Combobox的初步使用)所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
猜你在找的silverlight相关文章