ComboBox Selected Item couldn't calculated output Wpf - c#

I am creating a simple currency converter app in WPF C#. I need to convert the currency USD to Indian rupees or Srilankan rupees, but couldn't process the output.
Furthermore, I have done the design and code when I ran the application output not displayed and error also not displayed what was a problem I don't know. What I tried so far I attached the code below, please have a look.
WPF design
<Grid>
<Label Content="Amount :"
Grid.Row="0"
Grid.Column="0"/>
<TextBox x:Name="TextBoxAmount"
Grid.Row="0"
Grid.Column="1"/>
<Label Content="From :"
Grid.Row="2"
Grid.Column="0"/>
<ComboBox Name="CboFrom" HorizontalAlignment="Left" VerticalAlignment="Top" Width="100" Height="25" Grid.Row="2"
Grid.Column="1">
<ComboBoxItem Content="USD"/>
</ComboBox>
<Label Content="To :"
Grid.Row="4"
Grid.Column="0"/>
<ComboBox Name="CboTo" HorizontalAlignment="Left" VerticalAlignment="Top"
Width="100" Height="25" Grid.Row="4"
Grid.Column="1">
<ComboBoxItem Content="Srilankan Rupees"/>
<ComboBoxItem Content="Indian Rupees"/>
</ComboBox>
<Label Content="Total :"
Grid.Row="6"
Grid.Column="0"/>
<TextBox
x:Name="TextBoxTotal"
Grid.Row="6"
Grid.Column="1"/>
</Grid>
<StackPanel
Grid.Row="8"
Grid.ColumnSpan="2"
Orientation="Horizontal">
<Button
Width="60"
Height="30"
Content="Convert"
x:Name="ButtonConvert"
Margin="10 0 10 0"
Click="ButtonConvert_Click" Background="#FF04097E" Foreground="White"/>
</StackPanel>
C# Code
private void ButtonConvert_Click(object sender, RoutedEventArgs e)
{
double tot;
double amount = double.Parse(TextBoxAmount.Text);
if (CboFrom.SelectedItem == "USD" && CboTo.SelectedItem == "Srilankan Rupees")
{
tot = amount * 179.50;
TextBoxTotal.Text = tot.ToString();
}
else if (CboFrom.SelectedItem == "USD" && CboTo.SelectedItem == "Indian Rupees")
{
tot = amount * 70;
TextBoxTotal.Text = tot.ToString();
}
}

CboFrom.SelectedItem is not a string, it's a ComboBoxItem.
What you want to compare is ((ComboBoxItem)CboFrom.SelectedItem).Content.ToString().
Which gives you:
if (((ComboBoxItem)CboFrom.SelectedItem).Content.ToString() == "USD" && ((ComboBoxItem)CboTo.SelectedItem).Content.ToString() == "Srilankan Rupees")
Whilst that will work, it is definitely hacky and bad design. I advise you look into EldHasp's suggestions to improve your design.

You set a collection of UI elements in the ComboBox - ComboBoxItem. Therefore, you select a UI element. And it will not work to compare it with the value of the data.
According to the application logic, you need to set the data collection in the ComboBox source so that you can select this data.
In its simplest form, it would be something like this:
public static class SomeHelper
{
public static ReadOnlyCollection CurrencyСodes {get;} = Array.AsReadOnly(new string[] {"USD"});
public static ReadOnlyCollection CurrencyNames {get;} = Array.AsReadOnly(new string[] {"Srilankan Rupees", "Indian Rupees"});
}
<ComboBox x:Name="CboFrom" HorizontalAlignment="Left" VerticalAlignment="Top" Width="100" Height="25"
Grid.Row="2" Grid.Column="1"
ItemsSource="{x:Static local:SomeHelper.CurrencyСodes}"/>
<ComboBox x:Name="CboTo" HorizontalAlignment="Left" VerticalAlignment="Top" Width="100" Height="25"
Grid.Row="4" Grid.Column="1"
ItemsSource="{x:Static local:SomeHelper.CurrencyNames}"/>
private void ButtonConvert_Click(object sender, RoutedEventArgs e)
{
double tot;
double amount = double.Parse(TextBoxAmount.Text);
if (CboFrom.SelectedItem == SomeHelper.CurrencyСodes[0])
{
if (CboTo.SelectedItem == SomeHelper.CurrencyNames[0])
{
tot = amount * 179.50;
TextBoxTotal.Text = tot.ToString();
}
else if (CboTo.SelectedItem == SomeHelper.CurrencyNames[1])
{
tot = amount * 70;
TextBoxTotal.Text = tot.ToString();
}
}
}
P.S. But I would recommend that you implement a normal WPF-typical ViewModel. This will greatly simplify the code, make it easier to read and understand. Reduce the likelihood of various errors.

Related

Gidview item not updating

My page having city listing and searching functionality. When page first time loading, it is showing all record.
When user enter search Text and tap on search button. it is not updating gridview list. I check by placing debug point my code is working fine. but gridview list not showing updated list.
Following is my code.
XAML:
<StackPanel VerticalAlignment="Top">
<TextBlock Style="{StaticResource ListTextBlockStyle}" FontWeight="Bold" Text="{Binding Description}" />
<TextBlock Style="{StaticResource ListTextBlockStyle}" Text="{Binding Description}" />
</StackPanel>
<TextBlock Style="{StaticResource DistanceTextBlockStyle}" TextWrapping="Wrap" Text="XXXm" />
<Image Width="10" VerticalAlignment="Center" Source="ms-appx:///Assets/arrowright.png"/>
</StackPanel>
<Rectangle Height="1" Stroke="Black" StrokeThickness="0.5" Margin="0,3,0,0" />
</StackPanel>
</Border>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
<Border Grid.Row="1" Height="60" VerticalAlignment="Bottom">
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<TextBox x:Name="txtSearch" Margin="0,0,10,0" TextWrapping="Wrap" PlaceholderText="Search" VerticalAlignment="Center" Width="300" Height="50" />
<Image x:Name="imgSearch" Height="50" Width="50" Source="ms-appx:///Assets/btnSearch.png" Tapped="imgSearch_Tapped"/>
</StackPanel>
</StackPanel>
</Border>
C#:
public List<City> gs_CityList = new List<City>();
protected override void OnNavigatedTo(NavigationEventArgs e)
{
fillCityList();
}
private void fillCityList()
{
gs_CityList.Clear();
if (string.IsNullOrEmpty(CityListManagerManager.ms_searchTxt))
{
foreach (City foCity in CityListManagerManager.ms_CityList)
{
City loCity = new City();
loCity.Description = foCity.Description.Replace("\n", "").Substring(0, 15) + "...";
loCity.longtitude = foCity.longtitude;
loCity.latitude = foCity.latitude;
loCity.Location = foCity.Location;
gs_CityList.Add(loCity);
}
}
else
{
foreach (City foCity in CityListManagerManager.ms_CityList.Where(p => p.Description.ToLower().Contains(CityListManagerManager.ms_searchTxt.ToLower())))
{
City loCity = new City();
loCity.Description = foCity.Description.Replace("\n", "").Substring(0, 15) + "...";
loCity.longtitude = foCity.longtitude;
loCity.latitude = foCity.latitude;
loCity.Location = foCity.Location;
gs_CityList.Add(loAEDPin);
}
txtSearch.Text = CityListManagerManager.ms_searchTxt;
}
if (gs_CityList.Count > 0)
{
gvCityList.DataContext = gs_CityList; // --- This binding data to gridview
}
else
MessageBox("City not found...!");
}
private void imgSearch_Tapped(object sender, TappedRoutedEventArgs e)
{
CityListManagerManager.ms_searchTxt = txtSearch.Text.Trim();
fillCityList();
}
You should try changing your List<City> into an ObservableCollection<City>, as this allows the binding to get notified about changes.
You could also think about using a CollectionViewSource as data source for the GridView and modifying its Filter property instead of re-filling the collection.

Switch from one DataTemplate to other

In my wpf application, there is View class where I've ListBox. I wrote the code for double click event of ListBox Item.so when I double click on any list Box Item that item will be posted in my Harvest account.Here is the event:
private void listBox1_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
//Submit clicked Entry
try
{
ListBoxItem item = (ListBoxItem)sender;
Harvest_TimeSheetEntry entryToPost = (Harvest_TimeSheetEntry)item.DataContext;
if (!entryToPost.isSynced)
{
//Check if something is selected in selectedProjectItem For that item
if (entryToPost.ProjectNameBinding == "Select Project" && entryToPost.ClientNameBinding == "Select Client")
MessageBox.Show("Please select you Project and Client");
else
Globals._globalController.harvestManager.postHarvestEntry(entryToPost);
MessageBox.Show("Entry posted");
}
else
{
//Already synced.. Make a noise or something
MessageBox.Show("Already Synced;TODO Play a Sound Instead");
}
}
catch (Exception)
{ }
}
My xaml code:
<DataTemplate x:Key="DefaultDataTemplate">
<StackPanel Orientation="Horizontal" Width="596">
<TextBox Text="{Binding ClientNameBinding}" Background="Transparent" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="145"/>
<TextBox Text="{Binding ApplicationNameBinding}" Background="Transparent" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="90"/>
<TextBox Text="{Binding StartTimeBinding}" Background="Transparent" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="100"/>
<TextBox Text="{Binding StopTimeBinding}" Background="Transparent" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="60"/>
<TextBox Text="{Binding ProjectNameBinding}" Background="Transparent" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="130"/>
<TextBox Text="{Binding TaskNameBinding}" Background="Transparent" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="71"/>
</StackPanel>
</DataTemplate>
<!-- Editable DataTemplate -->
<DataTemplate x:Key="EditableDataTemplate">
<StackPanel Orientation="Horizontal" Width="596">
<ComboBox x:Name="ClientComboBox" SelectionChanged="ProjectComboBoxChanged" ItemsSource="{Binding Path=clientList, ElementName=MainWin}" SelectedValuePath="_id" DisplayMemberPath="_name" SelectedItem="{Binding ClientNameBindingClass, Mode=OneWayToSource}" Background="Yellow" Padding="0" Margin="0" BorderThickness="0" Width="145"/>
<TextBox Text="{Binding ApplicationNameBinding}" Background="Yellow" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="90"/>
<TextBox Text="{Binding StartTimeBinding}" Background="Yellow" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="100"/>
<TextBox Text="{Binding StopTimeBinding}" Background="Yellow" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="60"/>
<TextBox Text="{Binding TaskNameBinding}" Background="Yellow" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="130"/>
<ComboBox x:Name="ProjectComboBox" SelectionChanged="ProjectComboBoxChanged" ItemsSource="{Binding Path=projectList, ElementName=MainWin}" SelectedValuePath="_id" DisplayMemberPath="_name" SelectedItem="{Binding ProjectNameBindingClass, Mode=OneWayToSource}" Width="71" Background="Yellow" BorderThickness="0"/>
</StackPanel>
</DataTemplate>
<!-- DataTemplate Selector -->
<l:DayViewListDataTemplateSelector x:Key="templateSelector"
DefaultDataTemplate="{StaticResource DefaultDataTemplate}"
EditableDataTemplate="{StaticResource EditableDataTemplate}"/>
I've timer in my class which generates that EditableDataTemplate with two comboBoxes. My problem is, when I select Client and Project in ComboBoxes and double click on the entry, it's posted in my account but at that time I want it to convert from editableDataTemplate to DefaultDataTemplate (i.e those two comboboxes should become textboxes likewise in DefaultDataTemplate). How should I achieve this result?
I don't think the DataTemplateSelector offers a method of changing the data template on request, it is merely used to choose different templates for different types of data (not data states).
I think probably the best way would be to add a property, lets call it IsInEditMode, to your data model. You could then add both the TextBlock and the Combobox to your data template and toggle their visibility according to the value of IsInEditMode.
By the way: if you use the ListBox.SelectedItem property in your DoubleClick-eventhandler you can directly access the data model element without having to first get the ListBoxItem and then access
its data context.
private void listBox1_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
//Submit clicked Entry
try
{
if(listBox1.SelectedItem is Harvest_TimeSheetEntry)
{
Harvest_TimeSheetEntry entryToPost = (Harvest_TimeSheetEntry)listBox1.SelectedItem;
if (!entryToPost.isSynced)
{
//Check if something is selected in selectedProjectItem For that item
if (entryToPost.ProjectNameBinding == "Select Project" && entryToPost.ClientNameBinding == "Select Client")
MessageBox.Show("Please select you Project and Client");
else
Globals._globalController.harvestManager.postHarvestEntry(entryToPost);
MessageBox.Show("Entry posted");
entryToPost.IsInEditMode = true; //set edit mode!
}
}
else
{
//Already synced.. Make a noise or something
MessageBox.Show("Already Synced;TODO Play a Sound Instead");
}
}
catch (Exception)
{ }
}

Dynamic Column headers and Header count in Datagrid WPF

I am constructing a datagrid in my WPF application.ItemSource of the Datagrid is bounded to an IEnumerable collection. I donno the ViewModel of my project. When I bind my datagrid itemsource to the datagrid I get column headers and Row values on the fly.
I donno the headers. It might be anything. I need to display detailed information of the selected row in the datagrid in a grid.
To do this i need to bing SelectedItem.HeaderName to the textblock of the grid.
But what the issue here is I donno the name of the header. So i can't simply hardcode SelectedItem.Headername.
And number of columns may differ respectively. So my detailed view should also dynamic number Header names with its respective value when a row of my datagrid is selected.
As of now i have harcoded and seen the result in my xaml like below. because for a particular file i know their respective column headers,
<Label HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Grid.Row="0"
Grid.Column="0">Header2:
</Label>
<TextBlock Grid.Row="0"
Grid.Column="1"
Name="Header2"
Text="{Binding SelectedItem.date, ElementName=dataGrid1}"
Width="auto"
Height="auto"
HorizontalAlignment="Stretch"
VerticalAlignment="Center" />
<Label Grid.Row="0"
Grid.Column="2"
VerticalAlignment="Center">Header3:</Label>
<TextBlock Grid.Row="0"
Grid.Column="3"
Name="username"
Text="{Binding SelectedItem.Header3, ElementName=dataGrid1}"
Width="auto"
Height="auto"
HorizontalAlignment="Stretch"
VerticalAlignment="Center" />
<Label Grid.Row="0"
Grid.Column="4"
VerticalAlignment="Center">Header4:</Label>
<TextBlock Grid.Row="0"
Grid.Column="5"
Name="level"
Text="{Binding SelectedItem.header4, ElementName=dataGrid1}"
Width="auto"
Height="auto"
HorizontalAlignment="Stretch"
VerticalAlignment="Center" />
<Label Grid.Row="1"
Grid.Column="0"
VerticalAlignment="Center">Header5:</Label>
<TextBlock Grid.Row="1"
Grid.Column="1"
Name="logger"
Text="{Binding SelectedItem.header5, ElementName=dataGrid1}"
Width="auto"
Height="auto"
HorizontalAlignment="Stretch"
VerticalAlignment="Center" />
<Label Grid.Row="1"
Grid.Column="2"
VerticalAlignment="Center">Headr6:</Label>
<TextBlock Grid.Row="1"
Grid.Column="3"
Name="thread"
Text="{Binding SelectedItem.header6, ElementName=dataGrid1}"
Width="auto"
Height="auto"
HorizontalAlignment="Stretch"
VerticalAlignment="Center" />
Since i am a begginer i couldn't figure out how to do this. I will be glad if u try to help me. And suggest some concepts i need to read related to this dynamic column generation, Count, assigning dynamic column headers to other control in UI.
Thanks in advance!
I have made a small project contains dynamic generation of the grid (TextBlock + TextBox clollection) depending on DataGrid headers and object properties that made your collection in DataGrid. Hope that's what you are looking for. you can donwload it from my SkyDrive
XAML :
<Grid>
<StackPanel>
<StackPanel x:Name="myStackPanel" Orientation="Vertical"></StackPanel>
<DataGrid x:Name="myDataGrid" ItemsSource="{Binding MySource}" AutoGenerateColumns="True">
</DataGrid>
</StackPanel>
</Grid>
I have set this in Loaded event handler :
for (int i = 0; i < myDataGrid.Columns.Count; i++)
{
var childStackPanel = new StackPanel { Orientation = Orientation.Horizontal };
var myTextBlock = new TextBlock { Text = myDataGrid.Columns[i].Header + " : " };
var myTextBox = new TextBox { Width = 200 };
Type myType = typeof(Text);
IList<PropertyInfo> props = new List<PropertyInfo>(myType.GetProperties());
myTextBox.SetBinding(TextBox.TextProperty,
new Binding("SelectedItem." + props[i].Name) { ElementName = "myDataGrid" });
childStackPanel.Children.Add(myTextBlock);
childStackPanel.Children.Add(myTextBox);
myStackPanel.Children.Add(childStackPanel);
}
Text class :
public class TranslationText
{
private string _translation;
private bool _isTranslated;
public string Translation
{
get { return _translation; }
set
{
_translation = value;
}
}
public bool IsTranslated
{
get { return _isTranslated; }
set
{
_isTranslated = value;
}
}
}

Windows Phone 7 Navigation passing parameter

I have a list box like below.
<ListBox x:Name="CouponListBox" ItemsSource="{Binding Item}" SelectionChanged="CouponListBox_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding MerchantImage}" Height="73" Width="73" VerticalAlignment="Top" Margin="0,10,8,0"/>
<StackPanel Width="130">
<TextBlock Text="{Binding CustomerName}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
<TextBlock Text="{Binding MerchantName}" TextWrapping="Wrap" FontSize="20" Foreground="#FFC4C4C4" Padding="10" />
<TextBlock Text="{Binding Distance}" TextWrapping="Wrap" FontSize="16" Foreground="#FFC4C4C4" Padding="10" />
<TextBlock Text="{Binding DistanceInMinutes}" TextWrapping="Wrap" FontSize="16" Foreground="#FFC4C4C4" Padding="10" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
And I have a Change Event in .cs file which is
private void CouponListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// If selected index is -1 (no selection) do nothing
if (CouponListBox.SelectedIndex == -1)
return;
// Navigate to the new page
System.Diagnostics.Debug.WriteLine("this is a test::" + CouponListBox.SelectedItem.ToString());
NavigationService.Navigate(new Uri("/DetailsPage.xaml?selectedItem=" + CouponListBox.SelectedIndex, UriKind.Relative));
// Reset selected index to -1 (no selection)
CouponListBox.SelectedIndex = -1;
}
In DetailsPage I could able to print the item Index. But What I want is Customer ID passed in the URL like
"/DetailsPage.xaml?selectedItem=" + CouponListBox.SelectedIndex + "&customerId=" + couponId
Can anyone please tell me where I should include customerId in my XAML file? and that who can I call it in the function.
Thank you,
Karthik
Use this:
if (this.NavigationContext.QueryString.ContainsKey("customerId"))
{
string customerId = this.NavigationContext.QueryString["customerId"];
}
if (this.NavigationContext.QueryString.ContainsKey("selectedItem"))
{
string selectedItem = this.NavigationContext.QueryString["selectedItem"];
}
in the usercontrol's Loaded or other appropriate event.

WPF Setting Window Data Context

I'm a relative beginner with WPF so please bear with me. I have a simple app that converts farenheit values to celcius and vice versa. I thought I would have a play with refactoring this to MVVM so I moved everything from my code-behind to a separate class and then set the dataContext programmatically. However I'm getting a lot of ..'does not exist in context errors'. Where am I going wrong? Thanks
XAML
<Window x:Class="FarenheitCelciusConverter.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Temperature Converter" Height="500" Width="500"
xmlns:local="clr-namespace:FarenheitCelciusConverter">
<Grid HorizontalAlignment="Left" VerticalAlignment="Top" Height="473" Width="488">
<Label Height="28" HorizontalAlignment="Left" Margin="10,10,0,0" Name="lblF" VerticalAlignment="Top" Width="64" FontWeight="Bold">Farenheit</Label>
<Label Height="28" HorizontalAlignment="Left" Margin="10,42,0,0" Name="lblC" VerticalAlignment="Top" Width="64" FontWeight="Bold">Celcius</Label>
<TextBox Height="23" Margin="94,10,112,0" Name="tbFaren" VerticalAlignment="Top" Width="72" HorizontalAlignment="Left" />
<TextBox Height="23" Margin="94,42,112,0" Name="tbCelcius" VerticalAlignment="Top" Width="72" HorizontalAlignment="Left" />
<Button Margin="94,76,109,0" Name="btnConvert" Click="btnConvert_Click" Height="23" VerticalAlignment="Top" HorizontalContentAlignment="Center" Width="72" HorizontalAlignment="Left">Convert</Button>
<Image Name="image1" Stretch="Fill" Margin="94,112,240,228">
<Image.Source>
<BitmapImage DecodePixelWidth="200" UriSource="C:\Users\Winston\Pictures\thermometer.jpg"/>
</Image.Source>
</Image>
<TextBlock FontWeight="Bold" Height="21" Margin="195,12,173,0" Name="tblCelci" VerticalAlignment="Top" /><TextBlock FontWeight="Bold" Height="21" Margin="195,44,0,0" Name="tblFarenh" VerticalAlignment="Top" HorizontalAlignment="Left" Width="120" /><TextBlock FontWeight="Bold" Height="21" Margin="195,78,15,0" Name="tblCex" VerticalAlignment="Top" Foreground="Red" />
</Grid>
</Window>
Code behind
namespace FarenheitCelciusConverter
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
DataContext = new ConverterViewModel();
}
}
}
View Model
namespace FarenheitCelciusConverter
{
public class ConverterViewModel
{
private void btnConvert_Click(object sender, RoutedEventArgs e)
{
tblCex.Text = "";
try
{
if (tbCelcius.Text.Length != 0)
{
double celcius = Double.Parse(tbCelcius.Text);
if (celcius < 99999.0 && celcius > -99999.0)
{
tblFarenh.Text = Math.Round(1.8 * celcius + 32.0) + " F";
}
else
{
throw new OverflowException("Number limit exceeded!");
}
}
if (tbFaren.Text.Length != 0)
{
double farenh = Double.Parse(tbFaren.Text);
if (farenh < 99999.0 && farenh > -99999.0)
{
tblCelci.Text = Math.Round(0.555 * (farenh - 32.0)) + " C";
}
else
{
throw new OverflowException("Number limit exceeded!");
}
}
}
catch (Exception ex)
{
tblCex.Text = ex.Message;
}
}
}
}
When using MVVM data is passed back and forth from the View (Window1) and the ViewModel through Databinding. So each of your textboxes should be databound to a public property in your Viewmodel:
<TextBox Height="23" Margin="94,10,112,0" Name="tbFaren" VerticalAlignment="Top" Width="72" HorizontalAlignment="Left" Text="{Binding FahrenText}"/>
And your ViewModel will take the values in the properties, do something with them, and set the properties bound to the appropriate textboxes.
In this way, the Viewmodel is performing the logic and the View is interpreting the output according to the rules that you are giving it. Later on, you can change the rules in the View without messing with the ViewModel whereas using the codebehind often you have to explicitly set View settings alongside the program logic.
Also, be sure to implement iNotifyPropertyChanged on your ViewModel , otherwise the UI wont know when the databound property values have changed and it wont update. Check out this post for an example.
Also here is the MSDN article on Databinding in WPF.

Categories

Resources