Reputation: 514
i am trying to get textbox.suggetionsource form another class file, so how to achieve this
i want this code snippet in class file.my Autocompletetext source code is like below:
string[] stringArray = {car,jeep,..... etc};
and then i want to set textbox.suggetionsource=stringarray using above made class file so how to this ,please give suggetions
Upvotes: 0
Views: 275
Reputation: 2111
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; }
}
}
Xaml
<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>
Upvotes: 1