WPF XAML Object reference not set to an instance of an object - c#

I've encountered this problem during development, the problem the compiler gives, is that an object reference is not set, So it should be some kind of null pointer
<Window x:Class="BattleShip.MVVM.Views.NewGameSettings"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:viewModels="clr-namespace:BattleShip.MVVM.ViewModels"
mc:Ignorable="d"
Title="New Game" ResizeMode="NoResize" SizeToContent="WidthAndHeight" WindowStartupLocation="CenterScreen">
<Window.DataContext>
<viewModels:SettingsViewModel/>
</Window.DataContext><Grid>
<Grid.RowDefinitions>
<RowDefinition MinHeight="80" Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition MinHeight="30" Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="80" Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition MinWidth="80" Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="4" Source="{StaticResource Background}" Height="120" Stretch="Fill"/>
<Label
x:Name="HeightLabel"
Content="Height"
Grid.Column="1" Grid.Row="1"
Margin="0,10,0,0"/>
<Label
x:Name="WidthLabel"
Content="Width"
Grid.Column="1" Grid.Row="2"
Margin="0,10,0,0"/>
<Label
x:Name="DifficultyLabel"
Content="AI Difficulty"
Grid.Column="1" Grid.Row="3"
Margin="0,10,0,0"/>
<TextBox x:Name="LengthBox"
TextWrapping="NoWrap"
VerticalContentAlignment="Center"
IsInactiveSelectionHighlightEnabled="True"
Grid.Column="2"
Grid.Row="1"
HorizontalAlignment="Left"
Width="100"
Text="{Binding Height}"
Margin="0,10,0,0"/>
<TextBox x:Name="HeightBox"
TextWrapping="NoWrap"
VerticalContentAlignment="Center"
Text="{Binding Width}"
Grid.Column="2" Grid.Row="2"
HorizontalAlignment="Left"
Width="100"
Margin="0,10,0,0"/>
<ComboBox ItemsSource="{Binding Difficulties}"
SelectedItem="{Binding SelectedDifficulty}"
Grid.Column="2" Grid.Row="3"
VerticalContentAlignment="Center"
HorizontalAlignment="Left"
Width="100"
Margin="0,10,0,0"/>
<Button Grid.Column="1" Grid.Row="4" Grid.ColumnSpan="2" Content="Start" Margin="0,10,0,0" Command="{Binding StartGameCommand}"/>
</Grid>
This is the code where it gives the error (line of ). How can I solve this problem since I initialized this view model?

If you have correct ViewModel, the compiler error may be caused by Visual Studio's bug, happened in VS 2015,VS2013, etc.So the solution is :
Try to delete .suo file and then restart Visual Studio.

Related

How to do a list of square in GRID XAML?

I am trying to create a grid in XAML by the following:
GRID Type
I tried something like this but I have no ideea how to add the red squares.
Do I have to make a grid in grid?
Right now, I have this code
<Window x:Class="MonitorComenzi.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:MonitorComenzi"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" FontSize="30" TextAlignment="Center" FontWeight="Bold" Foreground="Black">Comenzi plasate</TextBlock>
<TextBlock Grid.Row="0" Grid.Column="1" FontSize="30" TextAlignment="Center" FontWeight="Bold" Foreground="Green">Comenzi preparate</TextBlock>
</Grid>
</Window>
You can make nested Grids, its absolutly fine, but a single StackPanel do the trick as well. Something like this:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" FontSize="30" TextAlignment="Center" FontWeight="Bold" Foreground="Black">Comenzi plasate</TextBlock>
<TextBlock Grid.Row="0" Grid.Column="1" FontSize="30" TextAlignment="Center" FontWeight="Bold" Foreground="Green">Comenzi preparate</TextBlock>
<StackPanel Orientation="Horizontal"
Margin="10"
Grid.Row="1"
Grid.Column="0">
<Rectangle Fill="Red" Width="30" Height="30" Margin="5 0"/>
<Rectangle Fill="Red" Width="30" Height="30" Margin="5 0"/>
<Rectangle Fill="Red" Width="30" Height="30" Margin="5 0"/>
<Rectangle Fill="Red" Width="30" Height="30" Margin="5 0"/>
</StackPanel>
</Grid>

Prism mvvm - TabControl does not display data

I'm using Prism. I have a ContextControl region, and a view associated with that region. Within the view is a TabControl. The controls are displaying data with no problem, but the controls within the TabControl are not displaying any data. I have tried setting the DataContext and ItemsSource(for the TabControl) , without success. The data to be displayed is from the SelectedSession class.
xaml
<!--session data grid-->
<Grid x:Name="SessionDataGrid"
Grid.Column="2"
Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ContentControl
Grid.Row="0"
Margin="0 0 0 0"
prism:RegionManager.RegionName="DataRegion"/>
</Grid>
View
<!--row 0-->
<Label x:Name="labelSessionData"
Content="Session Data"
Style="{DynamicResource LabelGeneric}"
Grid.Column="0"
Grid.Row="0"
HorizontalContentAlignment="Center"
Margin="1,2,0,0"/>
<!--row 1-->
<Label x:Name="labelSessionDataIdentifier"
Content="Identifier: "
Grid.Column="0"
Grid.Row="1"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Right"
Style="{DynamicResource LabelGeneric}"/>
<TextBox x:Name="textBoxSessionDataIdentifier"
Grid.Column="1"
Grid.Row="1"
HorizontalAlignment="Left"
Style="{DynamicResource textBoxDataN}"
Text="{Binding SelectedSession.Identifier, Mode=OneWay}"
Width="230"
Margin="0 4 0 3"/>
<Label x:Name="labelSessionDataCamera"
Content="Camera: "
Grid.Column="2"
Grid.Row="1"
HorizontalAlignment="Right"
HorizontalContentAlignment="Right"
Style="{DynamicResource LabelGeneric}"/>
<ComboBox x:Name="comboboxSessionDataCamera"
Grid.Column="3"
Grid.Row="1"
FlowDirection="LeftToRight"
HorizontalAlignment="Left"
HorizontalContentAlignment="Left"
IsEditable="True"
ItemsSource="{Binding Cameras}"
DisplayMemberPath="CameraName"
SelectedValue="{Binding SelectedSession.CameraId, Mode=TwoWay}"
SelectedValuePath="CameraId"
Style="{DynamicResource ComboboxData}"
Width="230"
Margin="0 0 0 0"/>
<!--row 3-->
<TabControl x:Name="tabControlSessionData"
Grid.Column="0"
Grid.ColumnSpan="4"
Grid.Row="3"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Margin="0,0,10,0"
Visibility="Hidden">
<TabItem Header="Analog">
<Grid Background="{StaticResource MainBackgroundColor}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="83"/>
<ColumnDefinition Width="8"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="10"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<!--row 0-->
<Label x:Name="labelSessionAnalogFilm"
Content="Film: "
Grid.Column="0"
Grid.ColumnSpan="2"
Grid.Row="0"
Style="{DynamicResource LabelGeneric}"
Margin="1,1,0,0"/>
<ComboBox x:Name="comboboxSessionAnalogFilm"
Grid.Column="2"
Grid.ColumnSpan="2"
Grid.Row="0"
ItemsSource="{Binding Films}"
DisplayMemberPath="FilmName"
SelectedValue="{Binding SelectedSession.FilmId, Mode=TwoWay}"
SelectedValuePath="FilmID"
Style="{DynamicResource ComboboxData}"
Margin="0 0 0 0"/>
<Label x:Name="labelSessionAnalogISO"
Content="ISO: "
Grid.Column="4"
Grid.Row="0"
HorizontalAlignment="Right"
HorizontalContentAlignment="Right"
Style="{DynamicResource LabelGeneric}"
Margin="2,1,0,0"/>
<TextBox x:Name="textBoxSessionAnalogFilmISO"
Grid.Column="5"
Grid.Row="0"
HorizontalAlignment="Left"
Style="{DynamicResource textBoxDataN}"
Text="{Binding FilmISO, Mode=TwoWay}"
Width="50"
Margin="0,4"/>
Any help would be appreciated.
I was getting the data from a DataGrid. Once I defined the columns for the data it started working.

how to update xaml in uwp

I have created a application for windows 10 (uwp) devices. I´m using the windows appstudio "designer". Now, I have to update the source code by a combobox and the correct eventhandler.
The combobox items contains different urls. After the selection changed, I have to parse entries from a url.
Layout-file:
<Page
x:Class="App.Pages.NeuigkeitenListPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:was_actions="using:AppStudio.Uwp.Actions"
xmlns:was_commands="using:AppStudio.Uwp.Commands"
xmlns:was_controls="using:AppStudio.Uwp.Controls"
xmlns:list_layouts="using:Wallfahrtsapp.Layouts.List"
xmlns:controls="App.Layouts.Controls"
xmlns:vm="using:App.ViewModels"
xmlns:triggers="using:App.Triggers"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
d:DataContext="{d:DesignData Source=/Assets/Design/DesignData.json, Type=vm:DesignViewModel, IsDesignTimeCreatable=true}"
mc:Ignorable="d">
<Page.Resources>
<was_controls:VisualBreakpoints x:Name="ResponsiveBehaviorsVBP" ConfigFile="/Assets/ResponsiveBehaviorsVBP.json"></was_controls:VisualBreakpoints>
</Page.Resources>
<Grid Background="{StaticResource AppBackground}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid Grid.Row="0" Grid.ColumnSpan="2" Background="{StaticResource AppBarBackground}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="48"/>
<TextBlock Grid.Row="0" Grid.Column="0" Margin="{Binding Active.pageTitleMargin, Source={StaticResource ResponsiveBehaviorsVBP}}" Text="{x:Bind ViewModel.PageTitle}" Foreground="{StaticResource AppBarForeground}" FontSize="{StaticResource AppTitleTextSizeDefault}" VerticalAlignment="Center" HorizontalAlignment="Left" TextTrimming="CharacterEllipsis" MaxLines="1"/>
<was_actions:ActionsCommandBar
x:Name="appBar"
ActionsSource="{x:Bind ViewModel.Actions}" Style="{StaticResource WasCommandBarStyle}"
Foreground="{StaticResource AppBarForeground}"
IsVisible="{x:Bind ViewModel.HasActions}"
Background="{StaticResource AppBarBackground}"
Grid.Row="{Binding Active.appBarRow, Source={StaticResource ResponsiveBehaviorsVBP}}"
Grid.Column="{Binding Active.appBarColumn, Source={StaticResource ResponsiveBehaviorsVBP}}"
Grid.ColumnSpan="{Binding Active.appBarColumnSpan, Source={StaticResource ResponsiveBehaviorsVBP}}" Opened="appBar_Opened">
</was_actions:ActionsCommandBar>
<ScrollViewer Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="3"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ProgressBar Grid.Row="1" Height="3" Margin="0,6,0,6" IsIndeterminate="True" Foreground="{StaticResource PageTitleForeground}" Visibility="{x:Bind ViewModel.IsBusy, Converter={StaticResource BoolToVisibilityConverter}, FallbackValue=Collapsed, Mode=OneWay}"/>
<was_controls:ErrorNotificationControl x:Uid="ListErrorNotificationControl" Grid.Row="2" ErrorVisibility="{x:Bind ViewModel.HasLoadDataErrors, Converter={StaticResource BoolToVisibilityConverter}, Mode=OneWay}" ErrorColor="{StaticResource PageTitleForeground}" Margin="10,0,18,0"/>
<list_layouts:ListContactCard Grid.Row="1" ItemsSource="{x:Bind ViewModel.Items, Mode=OneWay}" ItemClickCommand="{x:Bind ViewModel.ItemClickCommand}" OneRowModeEnabled="False" Margin="31,0,0,3" Grid.RowSpan="3" />
<ListBox></ListBox>
</Grid>
</ScrollViewer>
<TextBlock HorizontalAlignment="Left"
x:Name="source"
TextWrapping="Wrap"
Text="Newsquelle auswählen:"
VerticalAlignment="Top"
FontFamily="Segoe UI"
FontStyle="Oblique"
Padding="40" Margin="384,-30,0,0" Height="78"
/>
<ComboBox x:Name="sourceComboBox"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Width="200"
SelectionChanged="selectionChanged"
>
<ComboBoxItem Content="Url1"/>
<ComboBoxItem Content="Url2"/>
</ComboBox>
<controls:DataUpdateInformationControl Grid.Row="2" Grid.ColumnSpan="2" LastUpdateDateTime="{x:Bind ViewModel.LastUpdated, Mode=OneWay}" Color="{StaticResource PageTitleForeground}" Margin="8,4,8,4" HorizontalAlignment="Left" HasLocalData="{x:Bind ViewModel.HasLocalData}"/>
</Grid>
C#- file: Eventhandler
private void selectionChanged (object sender , SelectionChangedEventArgs args)
{
index = sourceComboBox.SelectedIndex;
Debug.WriteLine("selectionChangedEventMethod");
newsblogHTTP(index);
}
But how can I update my layout with the new content?
If you need more code snippets let´s see the repo for my project.
layout-file : https://github.com/MasterCoder1992/BlutWallfahrtWindows10/blob/version/march2k17Y/Wallfahrtsapp.W10/Pages/NeuigkeitenListPage.xaml
https://github.com/MasterCoder1992/BlutWallfahrtWindows10/blob/version/march2k17Y/Wallfahrtsapp.W10/Pages/NeuigkeitenListPage.xaml.cs
C#-Config file:
https://github.com/MasterCoder1992/BlutWallfahrtWindows10/blob/version/march2k17Y/Wallfahrtsapp.W10/Sections/NeuigkeitenConfig.cs
Thanks for your help!

Maximize a window --> the Grid should grow with the Window C# WPF

i have a short question.
I have a Grid definied like this :
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
In this Grid is a lot of stuff like Buttons, Textboxes, Menubar, Datagrid and so on.
My question is:
When i maximize the Window, how can i provide a growing Grid?
All the stuff in the Grid is coppled with the margin of the Grid, so if i manually resize the Grid the stuff still stay on the right place, so i just need to now how to let the Grid grow with the Window if the user clicks on this sqaure in the top right of the window to maximize it :)
Edit:
XAML Usercontroll:
<UserControl x:Class="View.PatientListView"
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:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
mc:Ignorable="d" d:DesignWidth="1625" Height="750">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Menu Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2" Width="Auto">
<MenuItem Header="Datei">
<!--<MenuItem.Icon>
<Image Source="datei.jpg" Width="20" Height="20"/>
</MenuItem.Icon>-->
<MenuItem Header="Suchoptionen" Click="MenuItem_Click" >
<MenuItem.Icon>
<Image Source="Suchfeld-Lupe.png"/>
</MenuItem.Icon>
</MenuItem>
</MenuItem>
</Menu>
<Grid Grid.Column="0" Grid.Row="1" Margin="-10,5,10,-5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1258*"/>
<ColumnDefinition Width="367*"/>
</Grid.ColumnDefinitions>
<TextBox x:Name="teingabe" x:FieldModifier="public" KeyboardNavigation.TabIndex="1" HorizontalAlignment="right" Height="23" Margin="0,40,130,0" TextWrapping="Wrap" Text="{Binding Suchstring, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Top" Width="230" ToolTip="Mehrere Eingaben (max. 3) durch "," Trennung: Datensatz1 , Datensatz2 , Datensatz3" TextAlignment="Left" Grid.Column="1">
<TextBox.InputBindings>
<KeyBinding Gesture="Enter"
Command="{Binding Searchcommand}" />
</TextBox.InputBindings>
</TextBox>
<TextBox x:Name="tAnrede" x:FieldModifier="public" KeyboardNavigation.TabIndex="9" HorizontalAlignment="Right" Height="23" Margin="0,400,190,0" TextWrapping="Wrap" Text="{Binding Anrede,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="170" IsEnabled="{Binding Einschalten}" VerticalAlignment="Top" TextAlignment="Left" Grid.Column="1"/>
<TextBox x:Name="tKostentraegerlk" x:FieldModifier="public" KeyboardNavigation.TabIndex="4" HorizontalAlignment="Right" Height="22" Margin="0,175,10,0" TextWrapping="Wrap" Text="{Binding Kostentraegerlk, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Top" Width="170" IsEnabled="{Binding Einschalten}" TextAlignment="Left" Grid.Column="1">
</TextBox>
<Button x:Name="start" Content="Suche" HorizontalAlignment="right" Margin="0,40,10,0" VerticalAlignment="Top" Width="110" Height="23" Command="{Binding Searchcommand}" Grid.Column="1">
</Button>
After this there only more controlls.
The Window XAML:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:View="clr-namespace:View"
x:Name="Window"
x:Class="StartApplication.MainWindow"
Title="Verwaltung" Height="773" Width="1632" Closing="Window_Closing" KeyDown="Window_KeyDown" >
<View:PatientListView x:Name="plistview" HorizontalAlignment="Left" VerticalAlignment="Top" Width="1622" Height="750"/>
</Window>
Edit:
NVM i saw my mistake ...
Wtf, im so blind. Sorry :(
the important stuff is where your grid is within. in the code below the grid resize with the window
<Window>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
</Grid>
</Window>

Native ComboBox not displaying choices correctly

EDIT: It seems that ListPicker is the way to go but I have had further problems with that detailed Microsoft.Phone.Controls.Toolkit ListPicker throws XamlParseException
I have the following ComboBox in code:
<ComboBox x:Name="Result" Grid.Column="6" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="Black" Background="White">
<ComboBoxItem Content="Win" />
<ComboBoxItem Content="Place" />
<ComboBoxItem Content="Lose" />
</ComboBox>
But it does not display as I would have expected. When you drop down the ComboBox the options don't appear, it's just like empty items. See below:
However, when an item is selected, it displays correctly and the correct index/item is returned. See below:
I'm sure there is something simple I have missed but can't put my finger on it.
EDIT: Ok I am posting the full code for this. I have a user control, OddsRow, that looks like this:
<UserControl xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit" x:Class="MojoPinBetOddsCalculator.OddsRow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
d:DesignHeight="480" d:DesignWidth="480">
<Grid x:Name="LayoutRoot" Background="{StaticResource PhoneChromeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="70"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50*"></ColumnDefinition>
<ColumnDefinition Width="70*"></ColumnDefinition>
<ColumnDefinition Width="30*"></ColumnDefinition>
<ColumnDefinition Width="70*"></ColumnDefinition>
<ColumnDefinition Width="70*"></ColumnDefinition>
<ColumnDefinition Width="70*" ></ColumnDefinition>
<ColumnDefinition Width="100*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock x:Name="RowNumber" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Center"></TextBlock>
<TextBox x:Name="OddsNumerator" Grid.Column="1" Width="90" Height="70" HorizontalAlignment="Center" TextAlignment="Center" VerticalAlignment="Center" MaxLength="3" InputScope="TelephoneNumber"></TextBox>
<TextBlock x:Name="Slash" Grid.Column="2" Text="/" HorizontalAlignment="Center" VerticalAlignment="Center"></TextBlock>
<TextBox x:Name="OddsDenominator" Grid.Column="3" Width="90" Height="70" VerticalAlignment="Center" TextAlignment="Center" MaxLength="3" HorizontalAlignment="Center" InputScope="TelephoneNumber"></TextBox>
<CheckBox x:Name="EachWay" Grid.Column="4" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="10,0,0,0" />
<CheckBox x:Name="Place" Grid.Column="5" HorizontalAlignment="Center" VerticalAlignment="Center" BorderThickness="0" Width="71" Margin="10,0,0,0" Padding="0" />
<ComboBox x:Name="Result" Grid.Column="6" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="Black" Background="White">
<ComboBoxItem Content="Win" />
<ComboBoxItem Content="Place" />
<ComboBoxItem Content="Lose" />
</ComboBox>
</Grid>
</UserControl>
And it is displayed in the MainPage like so:
<phone:PhoneApplicationPage xmlns:my="clr-namespace:MojoPinBetOddsCalculator"
x:Class="MojoPinBetOddsCalculator.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"
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">
<!--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="BET ODDS CALCULATOR" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="calculate" 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" HorizontalAlignment="Stretch">
<Grid x:Name="Scrollable">
<ScrollViewer>
<Grid x:Name="BettingGrid">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid x:Name="BetList">
<Grid.RowDefinitions>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="70"></RowDefinition>
<RowDefinition Height="70"></RowDefinition>
<RowDefinition Height="70"></RowDefinition>
<RowDefinition Height="70"></RowDefinition>
<RowDefinition Height="70"></RowDefinition>
<RowDefinition Height="70"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50*"></ColumnDefinition>
<ColumnDefinition Width="70*"></ColumnDefinition>
<ColumnDefinition Width="30*"></ColumnDefinition>
<ColumnDefinition Width="70*"></ColumnDefinition>
<ColumnDefinition Width="70*"></ColumnDefinition>
<ColumnDefinition Width="70*"></ColumnDefinition>
<ColumnDefinition Width="100*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Text="EW" Style="{StaticResource PhoneTextNormalStyle}" Grid.Row="0" Grid.Column="4" HorizontalAlignment="Center" />
<TextBlock Text="Place" Style="{StaticResource PhoneTextNormalStyle}" Grid.Row="0" Grid.Column="5" HorizontalAlignment="Center" />
<TextBlock Text="Result" Style="{StaticResource PhoneTextNormalStyle}" Grid.Row="0" Grid.Column="6" HorizontalAlignment="Center" />
<my:OddsRow Grid.Row="1" Grid.ColumnSpan="7" Row="1"/>
<my:OddsRow Grid.Row="2" Grid.ColumnSpan="7" Row="2"/>
<my:OddsRow Grid.Row="3" Grid.ColumnSpan="7" Row="3"/>
<my:OddsRow Grid.Row="4" Grid.ColumnSpan="7" Row="4"/>
<my:OddsRow Grid.Row="5" Grid.ColumnSpan="7" Row="5"/>
<my:OddsRow Grid.Row="6" Grid.ColumnSpan="7" Row="6"/>
</Grid>
<Grid x:Name="ControlsGrid" Grid.Row="1">
<Button x:Name="AddRowButton" Background="#BFFFFFFF" BorderBrush="#BFFFFFFF" Foreground="Black" Content="Add Row" FontSize="16" Click="AddRowButton_Click" Height="70" />
</Grid>
</Grid>
</ScrollViewer>
</Grid>
</Grid>
</Grid>
</phone:PhoneApplicationPage>
Separately the ComboBox works, and also the code for the OddsRow works as expected... separately. When combined it doesn't display the items.
OddsRow.xaml.cs
public partial class OddsRow : UserControl
{
private int m_Row;
public OddsRow()
{
InitializeComponent();
}
public int Row
{
get
{
return m_Row;
}
set
{
m_Row = value;
RowNumber.Text = m_Row + " - ";
}
}
}
For the love of everything, please do not use the stock ComboBox. Use something like ListPicker. It will make your application look more consistent with the Metro UI.

Categories

Resources