C# 如何设置自动完成textbox.suggetions类的自动完成值来源#
我试图从另一个类文件中获取textbox.suggetionsource,那么如何实现呢 我希望在类文件中包含此代码段。我的Autocompletetext源代码如下所示:C# 如何设置自动完成textbox.suggetions类的自动完成值来源#,c#,class,windows-phone-7,autocomplete,C#,Class,Windows Phone 7,Autocomplete,我试图从另一个类文件中获取textbox.suggetionsource,那么如何实现呢 我希望在类文件中包含此代码段。我的Autocompletetext源代码如下所示: string[] stringArray = {car,jeep,..... etc}; 然后我想使用上面生成的类文件设置textbox.suggetionsource=stringarray 那么如何做到这一点,请给出建议 名称空间测试用例 { 公共级康乃馨:IEnumerable { public IEnum
string[] stringArray = {car,jeep,..... etc};
然后我想使用上面生成的类文件设置textbox.suggetionsource=stringarray
那么如何做到这一点,请给出建议
名称空间测试用例
{
公共级康乃馨:IEnumerable
{
public IEnumerable AutoCompletions=新列表
{
新车{Name=“Astra”},
新车{Name=“奥迪”},
新车{Name=“Avant”},
新车{Name=“Bugatti”},
新车{Name=“Bentley”},
新车{Name=“BMW”},
新车{Name=“Bond”},
新车{Name=“Buckler”},
新车{Name=“Burney”},
新车{Name=“Chrysler”},
新车{Name=“Citroën”},
新车{Name=“Crossley”},
};
公共IEnumerator GetEnumerator()
{
返回自动完成。GetEnumerator();
}
}
公车
{
公共字符串名称{get;set;}
}
}
Xaml
namespace TestCase
{
public class CarNames : IEnumerable
{
public IEnumerable AutoCompletions = new List<Car>
{
new Car { Name = "Astra" },
new Car { Name = "Audi" },
new Car { Name = "Avant" },
new Car { Name = "Bugatti" },
new Car { Name = "Bentley" },
new Car { Name = "BMW" },
new Car { Name = "Bond" },
new Car { Name = "Buckler" },
new Car { Name = "Burney" },
new Car { Name = "Chrysler " },
new Car { Name = "Citroën" },
new Car { Name = "Crossley" },
};
public IEnumerator GetEnumerator()
{
return AutoCompletions.GetEnumerator();
}
}
public class Car
{
public string Name { get; set; }
}
<phone:PhoneApplicationPage
x:Class="TestCase.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
xmlns:local="clr-namespace:TestCase"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<phone:PhoneApplicationPage.Resources>
<local:CarNames x:Key="CarListKey" />
</phone:PhoneApplicationPage.Resources>
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<toolkit:AutoCompleteBox ValueMemberPath="Name" VerticalAlignment="Top" Name="CarModelNames" ItemsSource="{StaticResource CarListKey}">
<toolkit:AutoCompleteBox.ItemTemplate>
<DataTemplate>
<TextBlock Margin="8,0" Text="{Binding Name}"/>
</DataTemplate>
</toolkit:AutoCompleteBox.ItemTemplate>
</toolkit:AutoCompleteBox>
</Grid>
</Grid>