I'm normally used to asp.net where there is an method, where I can test on try/catch.
But here in Wpf I cannot figure out what to do. It isn't when I have a button and do some code in the codebehind part. That I can do. But when loading the page/usercontrol
When loading the list in the ListView - I load by Binding Categories_GetActive But what to do, if that get an error?
This I do in the designer and not the codebehind, so how do I make an try/catch so I can throw the exception to see what is wrong? And yes I have to ask, because I do not know how to change the list, so it throws an exception. So please forgive me :-) In the UserControl I have the following code
<UserControl x:Class="Views.Account.AccountObsoleteView"
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:local="clr-namespace:Views.Account"
xmlns:viewModel = "clr-namespace:ViewModel.Account;assembly=ViewModel"
mc:Ignorable="d"
d:DesignHeight="550" d:DesignWidth="1000">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="585" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="989" />
</Grid.ColumnDefinitions>
<!--<Border BorderThickness="1" BorderBrush="Red" />-->
<TabControl Grid.Row="0" Grid.Column="0" Style="{StaticResource tabControlSmall}">
<TabItem Header="Aktive" Style="{StaticResource tabItemSmall}" >
<!--Tab aktive/inaktive-->
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="537" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="475" />
<ColumnDefinition Width="490" />
</Grid.ColumnDefinitions>
<!--<Border BorderThickness="1" BorderBrush="Blue" Grid.ColumnSpan="2" />-->
<!--Row 0 Venstre halvdel-->
<ListView ItemsSource="{Binding Categories_GetActive}" Grid.Row="0" Grid.Column="0">
<ListView.View>
<GridView>
<GridViewColumn Header="Id" Width="50" DisplayMemberBinding="{Binding CategoryId}"/>
<GridViewColumn Header="Navn" Width="320" DisplayMemberBinding="{Binding CategoryName}"/>
<GridViewColumn Header="Global" Width="50" DisplayMemberBinding="{Binding CategoryIsGlobal}"/>
</GridView>
</ListView.View>
</ListView>
<Grid Grid.Row="0" Grid.Column="1">
<!--Row 0 højre halvdel-->
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="35" />
<RowDefinition Height="10" />
<RowDefinition Height="200" />
<RowDefinition Height="400" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="487" />
</Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal" Grid.Row="0" Grid.Column="0" Width="480">
<Label x:Name="LblMessageCategoryActive" Content="" BorderThickness="1" Height="50" />
</StackPanel>
<!--<Border BorderThickness="1" BorderBrush="Red" Grid.ColumnSpan="2" Grid.RowSpan="2" />-->
<StackPanel Orientation="Horizontal" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Top" Width="190">
<!--Row 1-->
<Button x:Name="BtnCategoryActiveInactive" Content="Inaktiv" Width="75" Margin="25 0 0 0" />
<Button x:Name="BtnCategoryActiveNew" Content="Ny" Width="75" Margin="5 0 0 0" />
</StackPanel>
<StackPanel Margin="10" Orientation="Vertical" Grid.Row="3" Grid.Column="0" HorizontalAlignment="Right" VerticalAlignment="Top" Width="427">
<Grid VerticalAlignment="Top" HorizontalAlignment="Right">
<Grid.RowDefinitions>
<RowDefinition Height="5" />
<RowDefinition Height="35" />
<RowDefinition Height="35" />
<RowDefinition Height="35" />
<RowDefinition Height="35" />
<RowDefinition Height="35" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="255" />
<ColumnDefinition Width="90" />
<ColumnDefinition Width="200" />
<ColumnDefinition Width="25" />
</Grid.ColumnDefinitions>
<!--<Border BorderThickness="1" BorderBrush="Blue" Grid.ColumnSpan="3" Grid.RowSpan="2" />-->
<!--Row 0-->
<Label Content="" Grid.Row="0" Grid.Column="0" />
<!--Row 1-->
<Rectangle Grid.Row="1" Grid.Column="1" Fill="#d3d0d0" />
<Rectangle Grid.Row="1" Grid.Column="2" Fill="#d3d0d0" />
<Rectangle Grid.Row="1" Grid.Column="3" Fill="#d3d0d0" />
<Label Content="Id:" Grid.Row="1" Grid.Column="1" HorizontalContentAlignment="Right" />
<Label x:Name="LblCategoryActiveId" Content="" Grid.Row="1" Grid.Column="2" HorizontalContentAlignment="Left" />
<!--Row 2-->
<Rectangle Grid.Row="2" Grid.Column="1" Fill="#e3e1e1" />
<Rectangle Grid.Row="2" Grid.Column="2" Fill="#e3e1e1" />
<Rectangle Grid.Row="2" Grid.Column="3" Fill="#e3e1e1" />
<Label Content="Navn:" Grid.Row="2" Grid.Column="1" HorizontalContentAlignment="Right" />
<TextBox x:Name="TxtCategoryActiveName" Grid.Row="2" Grid.Column="2" Height="25" />
<!--Row 3-->
<Rectangle Grid.Row="3" Grid.Column="1" Fill="#d3d0d0" />
<Rectangle Grid.Row="3" Grid.Column="2" Fill="#d3d0d0" />
<Rectangle Grid.Row="3" Grid.Column="3" Fill="#d3d0d0" />
<CheckBox x:Name="CbxCategoryActiveGlobal" Content="Global:" Grid.Row="3" Grid.Column="0" Margin="105,10,185,10" VerticalAlignment="Center" HorizontalContentAlignment="Left" Grid.ColumnSpan="3" />
<!--Row 4-->
<Rectangle Grid.Row="4" Grid.Column="1" Fill="#e3e1e1" />
<Rectangle Grid.Row="4" Grid.Column="2" Fill="#e3e1e1" />
<Rectangle Grid.Row="4" Grid.Column="3" Fill="#e3e1e1" />
<CheckBox x:Name="CbxCategoryActiveActive" Content="Aktiv:" Grid.Row="4" Grid.Column="0" Margin="105,10,185,10" VerticalAlignment="Center" HorizontalContentAlignment="Left" Grid.ColumnSpan="3" />
<!--Row 5-->
<Button x:Name="BtnCategoryActiveSave" Content="Gem" Width="150" Grid.Column="1" Margin="0 5 0 0" Grid.Row="5" Grid.ColumnSpan="5" HorizontalAlignment="Center" HorizontalContentAlignment="Center" />
</Grid>
</StackPanel>
</Grid>
</Grid>
</TabItem>
<TabItem Header="Inaktive" Style="{StaticResource tabItemSmall}" >
</TabItem>
</TabControl>
</Grid>
</UserControl>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Views.Account
{
/// <summary>
/// Interaction logic for AccountObsoleteView.xaml
/// </summary>
public partial class AccountObsoleteView : UserControl
{
public AccountObsoleteView()
{
InitializeComponent();
DataContext = new ViewModel.Account.CategoryViewModel();
}
}
}