How to start a radiobutton checked = true in a WPF MVVM application - c#

Hi Basically I have a WPF application using the MVVM pattern.
This is my ViewModel:
namespace enLoja.WPF.ViewModel.Relatórios
{
public class SEL_PG_C_ALIViewModel : ViewModelBase
{
private readonly ICAD_EF_C_ALIService _cadEfCAliService;
//Commands
public RelayCommand OnLoaded { get; set; }
public RelayCommand Gerar { get; set; }
public SEL_PG_C_ALIViewModel(ICAD_EF_C_ALIService cadEfCAliService)
{
_cadEfCAliService = cadEfCAliService;
IsDataLoaded = false;
OnLoaded = new RelayCommand(OnLoadedExecute);
Gerar = new RelayCommand(GerarExecute, GerarCanExecute);
}
public async void Load()
{
await Task.Factory.StartNew(() =>
{
IsDataLoaded = true;
RaisePropertyChanged("IsDataLoaded");
});
}
public bool CodigoChecked { get; set; }
public bool DescricaoChecked { get; set; }
public bool IsDataLoaded { get; set; }
#region Commands Execute
public void OnLoadedExecute()
{
Load();
}
public void GerarExecute()
{
var parameters = new Dictionary<string, string>();
if (CodigoChecked)
{
parameters.Add("Order", "Código");
}
if (DescricaoChecked)
{
parameters.Add("Order", "Descrição");
}
IEnumerable<CAD_EF_C_ALI> query = _cadEfCAliService.GetCAD_EF_C_ALI();
var empresaSelecionada = new List<CAD_EF_C_PAR> { ((App)Application.Current).EmpresaSelecionada };
var reportWindow = new REL_PG_C_ALI(query.ToList(), parameters, empresaSelecionada);
reportWindow.ShowDialog();
}
public bool GerarCanExecute()
{
return (IsDataLoaded);
}
#endregion
}
}
And this is my xaml:
<GroupBox x:Name="grbOrdenacao" Header="Ordenação"
Grid.Column="1"
Style="{StaticResource GroupBoxCadastro}" Foreground="#FF333333" BorderBrush="#FF959595" Margin="1,0"
VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Grid.ColumnSpan="3">
<StackPanel x:Name="SpnOrdem"
Orientation="Horizontal"
VerticalAlignment="Center" Margin="0,-4,0,0">
<RadioButton x:Name="rbnCodigo"
Style="{StaticResource RadioButtonCadastro}"
Content="Código" Margin="5,0" Foreground="#FF333333" FontSize="13"
IsChecked="{Binding CodigoChecked}"/>
<RadioButton x:Name="rbnDescricao"
Style="{StaticResource RadioButtonCadastro}"
Content="Descrição" Margin="20,0,5,0" Foreground="#FF333333" FontSize="13"
IsChecked="{Binding DescricaoChecked}"/>
</StackPanel>
</GroupBox>
My question is: How can I bring the radio-button rbnCodigo already marked as true?

Did you try initializing CodigoChecked to true in the ViewModel constructor?

Ed Plunkett has the correct answer just add the following to your constructor
CodigoChecked = true;
So your constructor should look like this:
public SEL_PG_C_ALIViewModel(ICAD_EF_C_ALIService cadEfCAliService)
{
_cadEfCAliService = cadEfCAliService;
IsDataLoaded = false;
OnLoaded = new RelayCommand(OnLoadedExecute);
Gerar = new RelayCommand(GerarExecute, GerarCanExecute);
CodigoChecked = true;
}

Related

(WPF)(MVVM) My ListViewItems are only updated when I change my view

I am creating an application with an MVVM model, in one of my views I have an ObservableCollection where by means of a button I create a new element and it appears on the screen, the problem is that I have a button to update that changes the name of the ListViewItem , and this name doesn't change until I switch between views
Problem
The DNP3-Master are my Items and the button I activate changes the name to "Test" but it is not updated until I change my view (this is a UserControl)
MasterViwModel
class MasterViewModel : ObservableObject
{
public ushort count { get; set; }
public ObservableCollection<MasterTraceModel> MasterReference { get; set; }
public RelayCommand CreateMaster { get; set; }
public RelayCommand Update { get; set; }
private ObservableCollection<MasterModel> _masterList;
public ObservableCollection<MasterModel> MasterList
{
get { return _masterList; }
set { _masterList = value; OnPropertyChanged(); }
}
private MasterModel _selectedMaster;//SelectedItem from ListView
public MasterModel SelectedMaster
{
get { return _selectedMaster; }
set { _selectedMaster = value; OnPropertyChanged(); }
}
public MasterViewModel()
{
MasterList = new ObservableCollection<MasterModel>();//my Observable Collections
//Stuff
this.count = 1;
//Stuff
CreateMaster = new RelayCommand(o =>
{
MasterList.Add(new MasterModel(this.count, "127.0.0.1", "20000", runtime));
this.count = (ushort)(count + 1);
});//Here I add the elements to my ObservableCollections
//Stuff
Update = new RelayCommand(o =>
{
SelectedMaster.SetName("Test");
});
}
}
MasterView
<UserControl x:Class="Prototype.MVVM.View.MasterView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:viewmodel="clr-namespace:Prototype.MVVM.ViewModel"
d:DataContext="{d:DesignInstance Type=viewmodel:MasterViewModel}"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<Border Margin="20,20,0,20" Background="#151515" CornerRadius="8">
<ListView Name="MasterListView" Margin="5"
ItemsSource="{Binding MasterList}"
SelectedItem="{Binding SelectedMaster}"
ItemContainerStyle="{StaticResource MasterTheme}"
Background="Transparent"
BorderThickness="0"
/>
</Border>
<StackPanel Grid.Column="1" Margin="0,20,0,0">
<Button Margin="0,0,0,10" Grid.Column="1" Style="{StaticResource SmallBtn}" Command="{Binding Update}">
<Image Height="24" Width="24" Source="/Icons/cil-reload.png" RenderOptions.BitmapScalingMode="NearestNeighbor"/>
</Button>
</StackPanel>
</Grid>
</UserControl>
MasterModel
class MasterModel : ObservableObject
{
public string Name { get; set; }
public ushort Adress { get; set; }
public string Host { get; set; }
public string Port { get; set; }
public Runtime _runtime { get; set; }
public MasterChannel channel { get; set; }
public ConnectStrategy CStrategy { get; set; }
public string[] Delay { get; set; }
public MasterModel(ushort Adress, string Host, string Port, Runtime runtime)
{
this.Name = "DNP3-Master-" + Adress.ToString();
this.Adress = Adress;
this.Host = Host;
this.Port = Port;
this._runtime = runtime;
CStrategy = new ConnectStrategy();
//CStrategy.MinConnectDelay = new TimeSp
Delay = new string[3];
Delay[0] = CStrategy.MinConnectDelay.ToString();
Delay[1] = CStrategy.MaxConnectDelay.ToString();
Delay[2] = CStrategy.ReconnectDelay.ToString();
this.channel = MasterChannel.CreateTcpChannel(//Stuff);
}
public void SetName(string name)
{
this.Name = name;
}
public void Star(Runtime runtime)
{
Task.Run(async () =>
{
try
{
await MasterFunctions.RunChannel(channel);
}
finally
{
runtime.Shutdown();
}
});
}
The MasterModel class should implement the INotifyPropertyChanged event and raise the PropertyChanged event for the data-bound property when you call SetName:
private string _name;
public string Name
{
get { return _name; }
set { _name = value; OnPropertyChanged(); }
}
Using an ObservableCollection<T> doesn't replace the need to implement INotifyPropertyChanged and raise change notifications for the individual items in the collection. It notifies the view when items are added to and removed from the collection only.

ObservableCollection not showing any items on ListView

I am trying to bind a ObservableCollection on a ListView ItemsSource but it doesn't show anything to me, tried binding inside code, on the xaml..
public partial class ReadPage : ContentPage
{
private CarregarClientes _CClientes = new CarregarClientes();
private MySQLCon _db = new MySQLCon();
private MySQLConOverloads _over = new MySQLConOverloads();
private MySQLiteCon _dbSqLiteCon = new MySQLiteCon();
private MySQLiteConOverloads _oversqlite = new MySQLiteConOverloads();
//MY OBSERVABLECOLLECTION DEFINITION -----------------------------
public ObservableCollection<Clientes> _ClientesList { get; set; }
private string _tabela = "Clientes";
public ReadPage()
{
InitializeComponent();
backBtn.Clicked += async (s, o) => await Navigation.PopModalAsync();
//Method used to populate the ObservableCollection (_ClientesList);
PopularObservableCollection();
}
I am defining the ObservableCollection inside my ReadPage class, then populating it with a method called PopularObservableCollection.
public void PopularObservableCollection()
{
_ClientesList = new ObservableCollection<Clientes>();
int quantidadeDados = _CClientes.CNumeroItems() -1;
List<string> id = _CClientes.Cid();
List<string> debito = _CClientes.CDebito();
List<string> endereco = _CClientes.CEndereco();
List<string> nome = _CClientes.CNome();
List<string> observacao = _CClientes.CObservacao();
List<string> saldo = _CClientes.CSaldo();
List<string> telefone = _CClientes.CTelefone();
for (int i = 0; i <= quantidadeDados; i++)
{
_ClientesList.Add(new Clientes
{
id = id[i],
Debito = debito[i],
Endereco = endereco[i],
Nome = nome[i],
Observacao = observacao[i],
Saldo = saldo[i],
Telefone = telefone[i]
});
}
}
Clientes.cs:
public class Clientes : BindableObject
{
public string id { get; set; }
public string Nome { get; set; }
public string Endereco { get; set; }
public string Telefone { get; set; }
public string Debito { get; set; }
public string Saldo { get; set; }
public string Observacao { get; set; }
}
XAML:
<ListView
BindingContext="{Binding Source={x:Reference MyPage}, Path=.}"
x:Name="readListView"
BackgroundColor="PaleVioletRed"
HasUnevenRows="True"
CachingStrategy="RecycleElement"
HorizontalOptions="FillAndExpand"
ItemsSource="{Binding _ClientesList}"
VerticalOptions="FillAndExpand"
ItemTapped="ReadListView_OnItemTapped">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid>
<Label Text="Id:" Grid.Row="0"/>
<Label Text="{Binding id}" Grid.Row="0" Margin="10,0,0,0"/>
<Label Text="{Binding Nome}" Grid.Row="1" />
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>

Binding a TreeView to a collection with different types of objects on same level

I want to bind my Treeview control to a collection that holds objects of type MeasurementResult. The MeasurementResult object itself has two collections, one for MeasurementInfo and one for DeviceInfo types.
After googling and searching on SO I found out that the best solution might be a CompositeCollection. The problem I have with that is that I just can't figure out how to define the (Hierarchical?!)DataTemplate's in a way that my data get shown in the Treeview in the way I want it.
Ultimately I would like to have a TreeView structure like that:
-MeasurementResult1
---MeasurementInformation
------MeasurementInformation1
------MeasurementInformation2
------MeasurementInformation3
---DeviceInformation
------DeviceInformation1
------DeviceInformation2
------DeviceInformation3
-MeasurementResult2
---MeasurementInformation
------MeasurementInformation1
------MeasurementInformation2
------MeasurementInformation3
---DeviceInformation
------DeviceInformation1
------DeviceInformation2
------DeviceInformation3
-MeasurementResultN
But the problem is that my current Treeview looks like that:
The nested properties for MeasurementData and DeviceData are not shown in my TreeView.
The code that I have so far, XAML:
<local:TreeViewSampleData x:Key="TreeViewSampleData"/>
<DataTemplate x:Key="MeasurementDataTemplate">
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<TextBlock Text="Finished: " Margin="0,0,10,0"/>
<TextBlock Text="{Binding Finished}" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Median: " Margin="0,0,10,0"/>
<TextBlock Text="{Binding Median}" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Maximum: " Margin="0,0,10,0"/>
<TextBlock Text="{Binding Maximum}" />
</StackPanel>
</StackPanel>
</DataTemplate>
<HierarchicalDataTemplate x:Key="DeviceDataTemplate" DataType="{x:Type local:DeviceData}" ItemTemplate="{StaticResource MeasurementDataTemplate}"
ItemsSource="{Binding MeasurementData}">
<TextBlock Text="{Binding Name}" />
</HierarchicalDataTemplate>
<HierarchicalDataTemplate x:Key="MeasurementResultTemplate" DataType="{x:Type local:MeasurementResult}" ItemTemplate="{StaticResource DeviceDataTemplate}"
ItemsSource="{Binding Measurements}">
<TextBlock Text="{Binding Name}" />
</HierarchicalDataTemplate>
<telerik:RadTreeView x:Name="tvMeasResults"
ItemsSource="{Binding Source={StaticResource TreeViewSampleData}, Path = MeasurementResults}"
ItemTemplate="{StaticResource MeasurementResultTemplate}"
>
</telerik:RadTreeView>
My related classes:
public class MeasurementResult
{
public string Name { get; set; } = "Measurement Result";
internal ObservableCollection<MeasurementInfo> MeasurementInfo { get; set; }
internal ObservableCollection<DeviceInfo> DeviceInfo { get; set; }
public CompositeCollection Measurements
{
get
{
var items = new CompositeCollection();
items.Add(new CollectionContainer { Collection = MeasurementInfo });
items.Add(new CollectionContainer { Collection = DeviceInfo });
return items;
}
}
public MeasurementResult()
{
MeasurementInfo = new ObservableCollection<MeasurementInfo>();
DeviceInfo = new ObservableCollection<DeviceInfo>();
}
}
public class MeasurementInfo
{
public string Name { get; set; } = "Measurement Information";
public ObservableCollection<MeasurementData> ThicknessData { get; set; }
public MeasurementInfo()
{
ThicknessData = new ObservableCollection<MeasurementData>();
}
}
public class MeasurementData
{
public DateTime Finished { internal set; get; }
public double Median { internal set; get; }
public double Maximum { internal set; get; }
public MeasurementData()
{
Finished = DateTime.Now;
Median = 150;
Maximum = 200;
}
}
public class DeviceInfo
{
public string Name { get; set; } = "Device Information";
public ObservableCollection<DeviceData> DeviceData { get; set; }
public DeviceInfo()
{
DeviceData = new ObservableCollection<DeviceData>();
}
}
public class DeviceData
{
public DateTime Finished { internal set; get; }
public int Port { internal set; get; }
public int Slot { internal set; get; }
public DeviceData()
{
Finished = DateTime.Now;
Port = 1;
Slot = 1;
}
}
What is wrong with my bindings? I guess the DataTemplates are wrong but I couldn't figure out how to define them to get my expected result.
This will allow you to add specific items to specific leaves and they will be concatenated by GetEnumerator so the TreeView presents things in the way you expected.
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace WpfApp1
{
public partial class MainWindow
{
public MainWindow()
{
InitializeComponent();
var item = new InformationTreeItem("ROOT")
{
Children =
{
new InformationTreeItem("Level 1")
{
DeviceInformation =
{
new DeviceInformation("Device 1/1"),
new DeviceInformation("Device 1/2")
},
MeasurementInformation =
{
new MeasurementInformation("Measure 1/1"),
new MeasurementInformation("Measure 1/2")
},
Children =
{
new InformationTreeItem("Level 2")
{
DeviceInformation =
{
new DeviceInformation("Device 2/1"),
new DeviceInformation("Device 2/2")
},
MeasurementInformation =
{
new MeasurementInformation("Measure 2/1"),
new MeasurementInformation("Measure 2/2")
},
Children =
{
new InformationTreeItem("Level 3")
}
}
}
}
}
};
DataContext = item;
}
}
public interface IInformation
{
string Description { get; }
}
public class InformationTreeItem : IEnumerable<IInformation>, IInformation
{
public InformationTreeItem(string description)
{
Description = description;
}
private InformationTreeItem(string description, IList<IInformation> children)
{
Description = description;
Children = children;
}
public IList<IInformation> Children { get; } = new List<IInformation>();
public IList<DeviceInformation> DeviceInformation { get; } = new List<DeviceInformation>();
public IList<MeasurementInformation> MeasurementInformation { get; } = new List<MeasurementInformation>();
public string Description { get; }
public IEnumerator<IInformation> GetEnumerator()
{
var list = new List<IInformation>();
if (DeviceInformation.Any())
{
list.Add(new InformationTreeItem(nameof(DeviceInformation), new List<IInformation>(DeviceInformation)));
}
if (MeasurementInformation.Any())
{
list.Add(new InformationTreeItem(nameof(MeasurementInformation), new List<IInformation>(MeasurementInformation)));
}
foreach (var child in Children)
{
list.Add(child);
}
return list.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public override string ToString()
{
return Description;
}
}
public class DeviceInformation : IInformation
{
public DeviceInformation(string description)
{
Description = description;
}
public string Description { get; }
public override string ToString()
{
return Description;
}
}
public class MeasurementInformation : IInformation
{
public MeasurementInformation(string description)
{
Description = description;
}
public string Description { get; }
public override string ToString()
{
return Description;
}
}
}

Listview Displaying Name space not values from class Phone 8.1 Runtime

I am trying to bind a simple Listview control using the folloiwng
<ListView x:Name="listView" ItemsSource="{Binding}">
<StackPanel Orientation="Horizontal" Width="292" Height="80">
<Border Height="60" Width="60" Margin="10,10,0,10">
<Image Source="/SampleImage.png" Stretch="UniformToFill"/>
</Border>
<StackPanel Orientation="Vertical" VerticalAlignment="Top" Margin="0,10,0,0">
<TextBlock Text="{Binding description}"
Margin="10,0,0,0" Width="180" Height="42"
TextTrimming="WordEllipsis" TextWrapping="Wrap" HorizontalAlignment="Left"/>
<TextBlock Text="{Binding Title}"
Margin="10,2,0,0" Width="180" Height="14"
TextTrimming="WordEllipsis" HorizontalAlignment="Left"
FontSize="9" Opacity="0.49"/>
</StackPanel>
</StackPanel>
</ListView>
But for some reason when I reference my list which is created as such
using Parse;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
namespace Curo.DataModel
{
public class curoLists : INotifyPropertyChanged
{
public curoLists()
{
}
public curoLists(String uniqueId, String title, String subtitle, String imagePath, String description, String content, string type)
{
this.UniqueId = uniqueId;
this.Title = title;
this.Subtitle = subtitle;
this.Description = description;
this.ImagePath = imagePath;
this.Content = content;
this.Type = type;
}
public curoLists(String uniqueId, String title, String subtitle, String imagePath, String description, String content, bool unread, Int32 status)
{
UniqueId = uniqueId;
Title = title;
Subtitle = subtitle;
Description = description;
ImagePath = imagePath;
Content = content;
Unread = unread;
Status = status;
}
private bool _unread;
private string _title;
public string UniqueId { get; private set; }
public string Title
{
get { return _title; }
set
{
_title = value;
NotifyPropertyChanged("Title");
}
}
public string Subtitle { get; private set; }
public string Description { get; private set; }
public string ImagePath { get; private set; }
public string Content { get; private set; }
public int Status { get; private set; }
public string Type { get; private set; }
public string ViewToUse { get; private set; }
public bool Unread
{
get { return _unread; }
set
{
_unread = value;
NotifyPropertyChanged("Unread");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
public static async Task<curoLists> CreateFromParseObject(ParseObject parseObject)
{
return await Task.Run<curoLists>(() =>
{
var mlist = new curoLists();
mlist.Title = parseObject.ObjectId;
if (parseObject.ContainsKey("name"))
{
mlist.Title = (string)parseObject["name"];
}
if (parseObject.ContainsKey("description"))
{
mlist.Description = (string)parseObject["description"];
}
if (parseObject.ContainsKey("image"))
{
mlist.ImagePath = (string)parseObject["image"];
}
if (parseObject.ContainsKey("type"))
{
string mtype = (string)parseObject["type"];
if (mtype == "N")
{
mlist.Type = "Notes";
mlist.ViewToUse = "Notes.Xaml";
}
}
return mlist;
});
}
}
}
It does not display the requested data instead it just displays the folowing. I populate my list in the following mannor
List<curoLists> cLists;
public ClientsManage()
{
this.InitializeComponent();
PopulatelistAsync();
}
public async Task PopulatelistAsync()
{
try
{
curoListsDal _db = new curoListsDal();
cLists = await _db.GetListsAync();
listView.ItemsSource = cLists;
}
catch (Exception ex)
{
}
}
But it just displays the name space and not the data Curo.DataModel.CuroLists. When i debug the data it is def their and correct spelling the only thing it complains about when i compiles is on my constructor i do not have the await command but that would not make the data not appear would it?.
ListView is single Column. So you must custom it with GridView. I also add Window_Loaded method with asyn, and own Dal:
XAML:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
Loaded="Window_Loaded">
<ListView x:Name="listView">
<ListView.View>
<GridView>
<GridViewColumn Width="140" Header="Game Name"
DisplayMemberBinding="{Binding Description}" />
<GridViewColumn Width="140" Header="Title"
DisplayMemberBinding="{Binding Title}" />
</GridView>
</ListView.View>
</ListView>
</Window>
Code behind:
public partial class MainWindow : Window
{
private List<curoLists> cLists;
public MainWindow()
{
InitializeComponent();
}
// decorate this method with asyn
private async void Window_Loaded(
object sender, RoutedEventArgs e)
{
await PopulatelistAsync();
}
public async Task PopulatelistAsync()
{
try
{
curoListsDal _db = new curoListsDal();
cLists = await _db.GetListsAync();
listView.ItemsSource = cLists;
}
catch (Exception ex)
{
}
}
}
public class curoListsDal
{
public async Task<List<curoLists>> GetListsAync()
{
return await
Task.Run<List<curoLists>>(
() =>
{
Thread.Sleep(2000); // long run
var result = new List<curoLists>();
for (var i = 0; i < 3; i++)
{
var id = Guid.NewGuid().ToString();
var mlist = new curoLists(id,
"title" + id, "subtitle", "imagePath",
"desc", "content", true, 1);
result.Add(mlist);
}
return result;
});
}
}
Hope this help.

How to select one list which is an item of another list c#

How to select only one of lists which is a part of List FeatList? One FeatList item consists of CurrencyTypes and Date. I need to add to CurList only that CurrencyTypes list where Date is equal to ListCtrl3.SelectedItem.
namespace PhoneApp1
{
public class CurrencyOfDate
{
public List<CurrencyType> CurrencyTypes;
public string Date { get; set; }
public override string ToString()
{
return Date;
}
}
public class CurrencyType
{
public string Name { get; set; }
public string Value { get; set; }
public override string ToString()
{
return Name;
}
}
public partial class MainPage : PhoneApplicationPage
{
List<CurrencyType> curList = new List<CurrencyType>();
public event PropertyChangedEventHandler PropertyChanged;
public void InvokePropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
public List<CurrencyType> CurList
{
get { return curList; }
set
{
curList = value;
InvokePropertyChanged("CurList");
}
}
List<CurrencyOfDate> featList = new List<CurrencyOfDate>();
public List<CurrencyOfDate> FeatList
{
get { return featList; }
set
{
featList = value;
InvokePropertyChanged("FeatList");
}
}
// Constructor
public MainPage()
{
InitializeComponent();
Dispatcher.BeginInvoke(() =>
{
_download_serialized_data("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml");
});
}
private async void _download_serialized_data(string url)
{
HttpClient webclient = new HttpClient();
try
{
var downloadedString =
await
webclient.GetStringAsync(
new Uri("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml"));
XElement xmlData = XElement.Parse(downloadedString);
XNamespace ns = "http://www.ecb.int/vocabulary/2002-08-01/eurofxref";
List<CurrencyOfDate> list = new List<CurrencyOfDate>();
foreach (XElement c in xmlData.Elements(ns + "Cube").Elements(ns + "Cube"))
list.Add(new CurrencyOfDate()
{
Date = c.Attribute("time").Value,
CurrencyTypes =
(from k in xmlData.Elements(ns + "Cube").Elements(ns + "Cube").Elements(ns + "Cube")
select new CurrencyType()
{
Name = k.Attribute("currency").Value,
Value = k.Attribute("rate").Value
}).ToList()
});
FeatList = list;
ListCtrl3.ItemsSource = FeatList;
foreach (var selItem in list.Where(selItem => ListCtrl3.SelectedItem.ToString() == selItem.Date))
{
CurList = selItem.CurrencyTypes.ToList();
FromList.ItemsSource = CurList;
break;
}
}
and xaml:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,511">
<toolkit:ListPicker ScrollViewer.VerticalScrollBarVisibility="Auto"
ItemsSource="{Binding CurList}"
x:Name="FromList"
Margin="10,0,240,0">
<toolkit:ListPicker.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock FontSize="30"
Text="{Binding Name}">
</TextBlock>
</StackPanel>
</DataTemplate>
</toolkit:ListPicker.ItemTemplate>
</toolkit:ListPicker>
</Grid>
<Grid>
<toolkit:ListPicker x:Name="ListCtrl3" ItemsSource="{Binding FeatList}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" HorizontalContentAlignment="Stretch" Margin="230,0,10,0">
<toolkit:ListPicker.ItemTemplate>
<DataTemplate>
<TextBlock TextWrapping="Wrap" Text="{Binding Date}"/>
</DataTemplate>
</toolkit:ListPicker.ItemTemplate>
</toolkit:ListPicker>
</Grid>

Categories