I have a gridview with the name "majorGridView" inside a gridview with the name "assessmenGridView" whose data is data binding
XAML:
<GridView x:Name="asesmenGridView">
<GridView.ItemTemplate>
<DataTemplate>
<UserControl>
<Grid>
<StackPanel
x:Name="judulStack"
Height="40">
<TextBlock
x:Name="judulT"
Text="{Binding Title}"/>
</StackPanel>
<GridView
x:Name="majorGridView">
<GridView.ItemTemplate>
<DataTemplate>
<UserControl>
<Grid>
<TextBlock
x:Name="kelasT"
Text="{Binding Major}"/>
</Grid>
</UserControl>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
</Grid>
</UserControl>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
How to display binding text on "majorGridView" ? Because if I use the code below, I will get an error message: "The name 'majorGridView' does not exist in the current context"
Code:
ObservableCollection<Ujian> ujiandatasource = new ObservableCollection<Ujian>();
ObservableCollection<Ujian> majordatasource = new ObservableCollection<Ujian>();
string urlPath = "https://pto.study.id/api/" + ((App)(App.Current)).AsesmenCode + "-do/s2/choose-exam/" + guru.ID;
var httpClient = new HttpClient(new HttpClientHandler());
httpClient.DefaultRequestHeaders.Add("Authorization",
string.Format("Bearer {0}", tkn));
var response = await httpClient.GetAsync(urlPath);
string jsonText = await response.Content.ReadAsStringAsync();
try
{
JsonArray jsonArray = JsonArray.Parse(jsonText);
foreach (JsonValue groupValue in jsonArray)
{
JsonObject groupObject = groupValue.GetObject();
JsonArray majorArray = groupObject["majors"].GetArray();
foreach(JsonValue majorValue in majorArray)
{
JsonObject majorObject = majorValue.GetObject();
string major = majorObject["major"].GetString();
Ujian ujian1 = new Ujian();
ujian1.Major = major + ", ";
majordatasource.Add(ujian1);
majorGridView.ItemsSource = majordatasource;
}
Ujian ujian = new Ujian();
ujian.Title = title;
ujiandatasource.Add(ujian);
asesmenGridView.ItemsSource = ujiandatasource;
}
Ujian.cs
class Ujian
{
public string Title { get; set; }
public string Major { get; set; }
}
}
The name 'majorGridView' does not exist in the current context"
majorGridView in the parent DataTemplate, so we can't access majorGridView with name directly. For this scenario, we often use nested collection apply the value generally. And here is similar case that you could refer to.
Related
I'm getting data from api via async task:
public async Task<PostModel.Post[]> GetPostsAsync()
{
var client = new HttpClient();
var uri = new Uri("link here");
var response = await client.GetAsync(uri);
if (response.IsSuccessStatusCode)
{
var jsonString = await response.Content.ReadAsStringAsync();
var rootObject = JsonConvert.DeserializeObject<PostModel.Post[]>(jsonString);
return rootObject;
}
else
return null;
}
Also I've created a simple vertical view:
<ContentPage.Content>
<ListView x:Name="MainView">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Vertical" HorizontalOptions="Fill" VerticalOptions="Fill" BackgroundColor="WhiteSmoke">
<Frame OutlineColor="Black">
<Label x:Name="Title" Text="{Binding Name}"/>
<Image x:Name="Image" Source="{Binding path}" />
</Frame>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage.Content>
Wrote a custom cell for displaying data:
public CustomCell()
{
//instantiate items in views
var Image = new Image();
var NameLabel = new Label();
var horizontalLayout = new StackLayout() { BackgroundColor = Color.WhiteSmoke };
//set bindings
NameLabel.SetBinding(Label.TextProperty, new Binding("Name"));
Image.SetBinding(Image.SourceProperty, new Binding("path"));
Image.HorizontalOptions = LayoutOptions.Center;
Image.HeightRequest = 600;
Image.WidthRequest = 600;
NameLabel.FontSize = 24;
//add views to the view hierarchy
horizontalLayout.Children.Add(NameLabel);
horizontalLayout.Children.Add(Image);
//add to parent view
View = horizontalLayout;
}
Now I'd like to populate layout from the async task dynamically. For example if task gets 6 items - create 6 cells with data from each of the async task items. Any suggestions how can i do it? I'm completely green in xamarin.forms and just started trying it.
in OnAppearing, just set the source for your ListView
MainView.ItemSource = await GetPostsAsync();
I have a JSON like this:
I want to show the "rating" of data in gridview using the image below:
For example, the rating value is 5, it will be displayed as follows:
and if the rating is 3, it will be displayed as follows:
and if the rating is 0, it will be displayed as follows:
code:
try
{
loading.Visibility = Visibility.Visible;
string urlPath1 = "http://.../results.json?module=listing&page=1&token=3f63-dc43-c8d5-eb45-8cbf-b72d-9d98-800f";
var httpClient1 = new HttpClient(new HttpClientHandler());
var values1 = new List<KeyValuePair<string, string>>
{
};
HttpResponseMessage response1 = await httpClient1.GetAsync(urlPath1);
response1.EnsureSuccessStatusCode();
if (!response1.IsSuccessStatusCode)
{
busyIndicator.IsActive = false;
RequestException();
}
string jsonText1 = await response1.Content.ReadAsStringAsync();
JsonObject jsonObject1 = JsonObject.Parse(jsonText1);
JsonArray jsonData1 = jsonObject1["data"].GetArray();
foreach (JsonValue groupValue1 in jsonData1)
{
JsonObject groupObject2 = groupValue1.GetObject();
string title = groupObject2["title"].GetString();
double rating = groupObject2["rating"].GetNumber();
ListingClass file1 = new ListingClass();
file.Title = title;
file1.Rating = Convert.ToInt32(rating);
listingDatasource.Add(file1);
}
itemGridView.ItemsSource = listingDatasource;
busyIndicator.IsActive = false;
}
catch (HttpRequestException ex)
{
busyIndicator.IsActive = false;
RequestException();
}
How do you show the rating using the picture?
Note:
The maximum value of the rating is 5
It seems you should be able to use the third-party control, such as the UWP-Composition-Rating-Control.
W should be able to set the your images to the FilledImage and EmptyImage property of the Rating control. Then we can bind the number of the Rating in ListingClass class to the Value of the Rating control.
For example:
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<GridView Name="itemGridView">
<GridView.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Title}"></TextBlock>
<controls:Rating x:Name="Devils"
Value="{Binding Rating}"
Maximum="5"
ItemHeight="60"
ItemPadding="24"
StepFrequency="1"
EmptyImage="ms-appx:///Assets/empty.png"
FilledImage="ms-appx:///Assets/filled.png" />
</StackPanel>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
</Grid>
I'm having a problem with a ListView for Windows Phone:
I'm using a databinding to display all items in a folder, but when I try to iterate through them, I don't get a control, but the class I use to get the items in the LocalFolder of the app (The subjectpicker class)!
SubjectPicker class:
class SubjectPicker {
public static async Task<List<SubjectPicker>> SubjectData() {
List<string> Names = new List<string>();
List<Brush> Colors = new List<Brush>();
List<string> Items = new List<string>();
List<List<TestOrTask>> TestsAndTasks = new List<List<TestOrTask>>();
StorageFolder LocalFolder = ApplicationData.Current.LocalFolder;
var files = await LocalFolder.GetFilesAsync();
foreach (var file in files) {
//await file.DeleteAsync();
List<TestOrTask> TAT = new List<TestOrTask>();
Names.Add(file.DisplayName);
bool readItems = false;
var contents = await FileIO.ReadLinesAsync(file);
foreach (var content in contents) {
if (content.Contains("Subject Color")) {
string colorname = content.Replace("Subject Color: ", "");
Colors.Add(ColorConverter.fromString_Brush(colorname));
}
else if (content == "<Items>") readItems = true;
else if (content == "</Items>") readItems = false;
if (readItems == true && content != "") {
// Layout: <Name>: <Score>/<Maximum>|<YYYY>/<MM>/<DD>
string name = content.Split(':')[0];
string Score = content.Split(':')[1].Replace(" ", "");
string Date = content.Split('|')[1];
TestOrTask TOT = new TestOrTask(
name,
double.Parse(Score.Split('/')[0]),
double.Parse(Score.Split('/')[1]),
new DateTime(
Int32.Parse(Date.Split('/')[0]),
Int32.Parse(Date.Split('/')[1]),
Int32.Parse(Date.Split('/')[2])));
TAT.Add(TOT);
}
}
Items.Add("Aantal Testen & Taken: " + TAT.Count.ToString());
TestsAndTasks.Add(TAT);
}
var data = new List<SubjectPicker>();
for (int i = 0; i < Names.Count; i++) {
data.Add(new SubjectPicker(Names[i], Colors[i], Items[i], TestsAndTasks[i]));
}
return data;
}
public SubjectPicker(string name, Brush color, string itemstotal, List<TestOrTask> TestsAndTasks) {
PickerName = name;
PickerColor = color;
ItemTotal = itemstotal;
this.TestsAndTasks = TestsAndTasks;
}
public string PickerName { get; set; }
public Brush PickerColor { get; set; }
public string ItemTotal { get; set; }
public List<TestOrTask> TestsAndTasks = new List<TestOrTask>();
}
Xaml Code:
<Page.Resources>
<DataTemplate x:Key="SubjectTemplate">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Border Margin="0,9.5,0,0" Background="Transparent" >
<Rectangle Height="50" Width="50" Fill="{Binding PickerColor}" RadiusX="5" RadiusY="5"/>
</Border>
<StackPanel Grid.Column="1" Margin="14.5,0,0,0">
<TextBlock Text="{Binding PickerName}" Style="{ThemeResource ListViewItemTextBlockStyle}" />
<TextBlock Text="{Binding ItemTotal}" Style="{ThemeResource ListViewItemSubheaderTextBlockStyle}" />
</StackPanel>
</Grid>
</DataTemplate>
</Page.Resources>
<Page.BottomAppBar>
<CommandBar x:Name="AppBar" Visibility="Collapsed">
<AppBarButton x:Name="EditSubject" Icon="Edit" Label="Aanpassen" Click="EditSubject_Click"/>
<AppBarButton x:Name="DeleteSubject" Icon="Delete" Label="Verwijderen" Click="DeleteSubject_Click"/>
</CommandBar>
</Page.BottomAppBar>
<Grid x:Name="MainGrid" Loaded="MainGrid_Loaded">
<Controls:TopBarControl x:Name="TopBarControl" Margin="0" VerticalAlignment="Top" PageName="Vakken" ControlsVisible="All" Width="Auto" BackButtonClicked="TopBar_BackButtonClicked" AddButtonClicked="TopBar_AddButtonClicked" EditButtonClicked="TopBar_EditButtonClicked"/>
<Grid x:Name="ControlsGrid" Margin="0,50,0,-60" Tapped="ControlsGrid_Tapped">
<ListView x:Name="SubjectList" ItemsSource="{Binding}" ItemTemplate="{StaticResource SubjectTemplate}"/>
</Grid>
</Grid>
Void to iterate through:
private async Task SelectSubjects() {
for (int i = 0; i < SubjectList.Items.Count; i++) {
var control = SubjectList.Items[i];
Grid subject = control as Grid;
if (subject != null) {
subject.Background = new SolidColorBrush(SchoolToolsColors.AppColor);
await Task.Delay(TimeSpan.FromMilliseconds(50));
}
}
isSelecting = true;
AppBarVisible = Visibility.Visible;
}
Thanks in advance!!!
When iterating on databinded control you'll always get its underlying data.
You should Style.Triggers to alter UI based on data (changing background, showing/hiding controls, etc.).
However, there is a way to go with altering UI from C# but that would make XAML and code-behind tightly coupled => that introduces more complexity into your code - simply believe me, it is not what you want/need.
i have a huge problem....
i have a MainWindow.xaml. this xaml is seperated into differnt columns and rows. in. on the left side i have my different buttons. on the right side i have my so called content grid. in this content grid i open my different user controls by pressing a button.
in one of these user controls i request a route from A to B. if the points are excatly identified the route gets displays in the listbox below the input screen.
but if one of the two points isn't exactly identified i open a new window with two comboboxes where you have to specify and select your inputs. after choosing your start and destination points. the window should be closed by pressing the button OK and in the listbox in the user control the route should bey displayed....but it doesn't...
my english isn't that good and i hope you can help me by posting the code..
The Code behind file of the User Control:
RoutenplanungSelection rps = new RoutenplanungSelection();
public void checkStationsnamenSindEindeutig(string von, string nach, string datum, string zeit, bool abfahrt)
{
WebClient wc = new WebClient();
wc.Encoding = Encoding.UTF8;
string data = wc.DownloadString(....url);
var xe = XElement.Parse(data);
var CountOrigins = from a in xe.Descendants("itdOdv")
where a.Attribute("usage").Value == "origin"
select a.Element("itdOdvName").Elements("odvNameElem").Count();
var CountDestinations = from a in xe.Descendants("itdOdv")
where a.Attribute("usage").Value == "destination"
select a.Element("itdOdvName").Elements("odvNameElem").Count();
int countorigins = 0;
foreach (var c in CountOrigins)
countorigins = Convert.ToInt32(c);
int countdestinations = 0;
foreach (var c in CountDestinations)
countdestinations = Convert.ToInt32(c);
if (countorigins == 1 && countdestinations == 1)
{
downloadEindeutigenXml(von, nach, datum, zeit, abfahrt);
}
if (countorigins > 1 || countdestinations > 1)
{
var getAllOrigins = from a in xe.Descendants("itdOdv")
where a.Attribute("usage").Value == "origin"
select a;
var getAllDestinations = from a in xe.Descendants("itdOdv")
where a.Attribute("usage").Value == "destination"
select a;
foreach(var r in getAllOrigins)
rps.uebergebeXmlOrigins(r);
foreach (var r in getAllDestinations)
rps.uebergebeXmlDestination(r);
rps.uebergebeAllgemeineInfos(datum, zeit, abfahrt);
rps.Show();
}
}
public async void downloadEindeutigenXml(string von, string nach, string datum, string zeit, bool abfahrt)
{
WebClient wc = new WebClient();
wc.Encoding = Encoding.UTF8;
if(abfahrt)
{
this.mw = (MainWindow)Application.Current.MainWindow;
mw.progress.IsIndeterminate = false;
mw.progress.IsIndeterminate = true;
formatEindeutigeData(XElement.Parse(await wc.DownloadStringTaskAsync(
"....url")));
mw.progress.IsIndeterminate = false;
}
else
{
this.mw = (MainWindow)Application.Current.MainWindow;
mw.progress.IsIndeterminate = false;
mw.progress.IsIndeterminate = true;
formatEindeutigeData(XElement.Parse(await wc.DownloadStringTaskAsync(
"....url")));
mw.progress.IsIndeterminate = false;
}
}
private string addZeros(string number)
{
if (number.Length < 2)
return number.Insert(0, "0");
else
return number;
}
private void formatEindeutigeData(XElement xml)
{
box.Items.Clear();
var checkConnections = (from a in xml.Descendants("itdMessage")
where a.Attribute("code").Value == "-4000"
select a).Count();
var checkDateValid = (from a in xml.Descendants("itdMessage")
where a.Attribute("code").Value == "-4001"
select a).Count();
if (checkConnections == 1)
{
TextBlock nothing = new TextBlock();
nothing.TextAlignment = TextAlignment.Center;
nothing.HorizontalAlignment = HorizontalAlignment.Center;
nothing.FontSize = 18;
nothing.Text = "\n\n\nLeider gibt es keine Verbindung zu Ihrem gewünschten Ziel! :-(";
box.Items.Add(nothing);
}
if (checkDateValid == 1)
{
TextBlock nothing = new TextBlock();
nothing.TextAlignment = TextAlignment.Center;
nothing.HorizontalAlignment = HorizontalAlignment.Center;
nothing.FontSize = 18;
nothing.Text = "\n\n\nDatum außerhalb der Fahrplanperiode! :-(";
box.Items.Add(nothing);
}
var result = (from a in xml.Descendants("itdRouteList").Elements("itdRoute")
select new
{
partialRoute = from b in a.Descendants("itdPartialRouteList").Elements("itdPartialRoute")
select new
{
von = from c in b.Elements("itdPoint")
where c.Attribute("usage").Value == "departure"
select new
{
station = c.Attribute("name").Value,
abfahrtdatum_jahr = c.Element("itdDateTimeTarget").Element("itdDate").Attribute("year").Value,
abfahrtdatum_monat = c.Element("itdDateTimeTarget").Element("itdDate").Attribute("month").Value,
abfahrtdatum_tag = c.Element("itdDateTimeTarget").Element("itdDate").Attribute("day").Value,
abfahrtdatum_stunde = addZeros(c.Element("itdDateTimeTarget").Element("itdTime").Attribute("hour").Value),
abfahrtdatum_minute = addZeros(c.Element("itdDateTimeTarget").Element("itdTime").Attribute("minute").Value)
},
nach = from c in b.Elements("itdPoint")
where c.Attribute("usage").Value == "arrival"
select new
{
station = c.Attribute("name").Value,
ankuftdatum_jahr = c.Element("itdDateTimeTarget").Element("itdDate").Attribute("year").Value,
ankuftdatum_monat = c.Element("itdDateTimeTarget").Element("itdDate").Attribute("month").Value,
ankuftdatum_tag = c.Element("itdDateTimeTarget").Element("itdDate").Attribute("day").Value,
ankuftdatum_stunde = addZeros(c.Element("itdDateTimeTarget").Element("itdTime").Attribute("hour").Value),
ankuftdatum_minute = addZeros(c.Element("itdDateTimeTarget").Element("itdTime").Attribute("minute").Value)
},
fahrmittel = from c in b.Elements("itdMeansOfTransport")
select new
{
name_plus_linie = c.Attribute("name").Value,
linie = c.Attribute("shortname").Value,
symbol = c.Attribute("symbol").Value,
richtung = c.Attribute("destination").Value
}
},
fahrzeit = a.Element("seqRoutes").Element("seqRoute").Attribute("publicDuration").Value
}).ToList();
foreach (var r in result)
{
foreach (var q in r.partialRoute)
{
foreach (var s in q.von)
{
foreach (var t in q.nach)
{
foreach (var a in q.fahrmittel)
{
//MessageBox.Show("von: " + s.ToString() + " nach: " + t.ToString() + " mittels " + a.name_plus_linie + " richtung " + a.richtung + "fahrzeit: " + r.fahrzeit);
TextBlock tb_name_linie_richtung = new TextBlock();
tb_name_linie_richtung.FontSize = 18;
if (a.name_plus_linie != "" && a.richtung != "")
tb_name_linie_richtung.Text = a.name_plus_linie + ", Richtung " + a.richtung;
else
tb_name_linie_richtung.Text = "Fußweg";
box.Items.Add(tb_name_linie_richtung);
}
TextBlock uhrzeit_von = new TextBlock();
uhrzeit_von.Text = s.abfahrtdatum_stunde + ":" + s.abfahrtdatum_minute + " " + s.station;
box.Items.Add(uhrzeit_von);
TextBlock uhrzeit_nach = new TextBlock();
uhrzeit_nach.Text = t.ankuftdatum_stunde + ":" + t.ankuftdatum_minute + " " + t.station;
box.Items.Add(uhrzeit_nach);
}
}
}
box.Items.Add(new TextBlock().Text = "\n\n");
}
}
XAML of the user control:
<UserControl x:Class="WLive.Routenplanung"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
xmlns:Controls="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:ControlsExtended="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:local="clr-namespace:WLive">
<UserControl.Resources>
<local:FontSizeConverter x:Key="fontSizeCon" />
</UserControl.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="8*"/>
<ColumnDefinition Width="92*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="11*"/>
<RowDefinition Height="11*"/>
<RowDefinition Height="8*" />
<RowDefinition Height="10*"/>
<RowDefinition Height="8*"/>
<RowDefinition Height="52*"/>
</Grid.RowDefinitions>
<Label Content="Von: " Grid.Column="0" FontSize="18" Grid.Row="0" />
<toolkit:AutoCompleteBox x:Name="tbvon" Grid.Row="0" Grid.Column="1" FilterMode="Contains" MinimumPrefixLength="4"
FontSize="{Binding Path=ActualHeight, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Grid}, Converter={StaticResource fontSizeCon}}" TextChanged="routevon_TextChanged"/>
<Label Content="Nach: " Grid.Column="0" FontSize="18" Grid.Row="1"/>
<toolkit:AutoCompleteBox x:Name="tbnach" Grid.Row="1" Grid.Column="1" FilterMode="Contains" MinimumPrefixLength="4"
FontSize="{Binding Path=ActualHeight, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Grid}, Converter={StaticResource fontSizeCon}}" TextChanged="routenach_TextChanged"/>
<RadioButton x:Name="radioabf" Grid.Row="2" Grid.ColumnSpan="2" Content="Abfahrt" FontSize="18" IsChecked="True"/>
<RadioButton x:Name="radioank" Grid.Row="2" Grid.ColumnSpan="2" Content="Ankunft" FontSize="18" Margin="100 0 0 0"/>
<StackPanel Grid.Row="3" Grid.ColumnSpan="2">
<ControlsExtended:DateTimePicker x:Name="datumsscheisse"></ControlsExtended:DateTimePicker>
</StackPanel>
<Button x:Name="butabfragen" Grid.Row="4" Grid.ColumnSpan="2" FontSize="18" Content="Route berechnen" HorizontalAlignment="Right" Click="abfragen_Click" />
<ListBox x:Name="box" Grid.Row="5" Grid.ColumnSpan="2">
</ListBox>
</Grid>
the code behind file of the routenplanungSelection
private string datum;
public string Datum
{
get { return datum; }
set { datum = value; }
}
private string zeit;
public string Zeit
{
get { return zeit; }
set { zeit = value; }
}
private bool abfahrt;
public bool Abfahrt
{
get { return abfahrt; }
set { abfahrt = value; }
}
public RoutenplanungSelection()
{
InitializeComponent();
}
public void uebergebeXmlOrigins(XElement xml)
{
var getAllOrigins = from a in xml.Descendants("odvNameElem")
select new
{
id = a.Attribute("id").Value,
name = a.Value
};
foreach (var r in getAllOrigins)
{
comboabfahrt.ItemsSource = getAllOrigins;
}
}
public void uebergebeXmlDestination(XElement xml)
{
var getAllDestinations = from a in xml.Descendants("odvNameElem")
select new
{
id = a.Attribute("id").Value,
name = a.Value
};
foreach (var r in getAllDestinations)
{
comboziel.ItemsSource = getAllDestinations;
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
string abfahrtid = comboabfahrt.SelectedValue.ToString();
string zielid = comboziel.SelectedValue.ToString();
new Routenplanung().downloadEindeutigenXml(abfahrtid, zielid, Datum, Zeit, Abfahrt);
}
public void uebergebeAllgemeineInfos(string datum, string zeit, bool abfahrt)
{
Datum = datum;
Zeit = zeit;
Abfahrt = abfahrt;
}
XAML of the window:
<Controls:MetroWindow x:Class="WLive.RoutenplanungSelection"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Controls="http://metro.mahapps.com/winfx/xaml/controls"
Title="WLive - Routenplanung, Haltestellenspezifikation" Height="230" Width="400" MinHeight="230" MinWidth="400">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="15*"/>
<ColumnDefinition Width="85*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<Label Content="Bitte spezifizieren Sie Ihre Eingaben:" FontSize="18" Foreground="Red" FontWeight="Bold" Grid.Row="0" Grid.Column="1"/>
<Label Content="Von:" Grid.Column="0" Grid.Row="1" FontSize="24" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
<Label Content="Nach:" Grid.Column="0" Grid.Row="2" FontSize="20" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
<ComboBox x:Name="comboabfahrt" Grid.Column="1" Grid.Row="1" DisplayMemberPath="name" SelectedValuePath="id" SelectedIndex="0" />
<ComboBox x:Name="comboziel" Grid.Column="1" Grid.Row="2" DisplayMemberPath="name" SelectedValuePath="id" SelectedIndex="0" />
<Button Grid.Row="3" Margin="0 5 5 5" HorizontalAlignment="Right" FontSize="20" Grid.Column="1" Click="Button_Click">OK</Button>
</Grid>
my aim is if the new window appears, i specifiy my station, the i click on OK, the window closes and in the listbox my result gets displays.
everything works, cause if i say MessageBox.Show(xml.ToString()); in the formatData(XElement xml) Method it displays me the right xml file...but it doesn't appear in the listbox....
Take a look to the Button_Click method of your RoutenplanungSelection window: first you retrive a couple of selected values, then you create a new instance of Routenplanung window.
Of course that new instance is not the same instance of the main window you see on the screen. In your secondary window you should have a reference to the main one.
listpicker shows object name instead of property.I'm already try all the solution which already given in stackoverflow but i dn't get any result
BorderThickness="0.2" SelectionMode="Multiple" SelectionChanged="AreaClassification_SelectionChanged"
VerticalAlignment="Bottom" Margin="204,-53,0,0" BorderBrush="Black" >
<toolkit:ListPicker.ItemTemplate>
<DataTemplate>
<StackPanel >
<TextBlock Text="{Binding name}" Foreground="Black" FontSize="18"/>
</StackPanel>
</DataTemplate>
</toolkit:ListPicker.ItemTemplate>
<toolkit:ListPicker.FullModeItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding name}" FontSize="18" Foreground="White" />
</StackPanel>
</DataTemplate>
</toolkit:ListPicker.FullModeItemTemplate>
</toolkit:ListPicker>
I just need to learn how to design a control.any reference do you have?
CodeBehind
string result = e.Result;
JObject o = JObject.Parse(result);
var results = o["Data"]["Area"];
JArray obj = results as JArray;
var dt = obj.ToArray();
foreach (var d in dt)
{
Area dts = new Area();
dts.code = Convert.ToString(d["code"]);
dts.name = Convert.ToString(d["name"]);
_lst.Add(dts);
}
AreaClassification.ItemsSource = _lst;
After lot of research i found this
AreaClassification.SummaryForSelectedItemsDelegate += SummarizeTeams;
protected string SummarizeTeams(IList selection)
{
string str = "*None Selected*";
if (null != selection && selection.Count > 0)
{
StringBuilder contents = new StringBuilder();
int idx = 0;
foreach (object o in selection)
{
if (idx > 0) contents.Append(", ");
contents.Append(((Area)o).name);
idx++;
}
str = contents.ToString();
}
return str;
}
To Show List Of Item We Need to use SummaryForSelectedItemsDelegate method on c#.I hope It's will help others