How to do a list of square in GRID XAML? - c#

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>

Related

How to add empty UserControl of StackPanel programmatically in WPF

I have a UserControl, empty StackPanel like following.
<Grid>
<StackPanel x:Name="datawrapper" Orientation="Horizontal" Background="Yellow"/>
</Grid>
Main window's XAML is like following.
<ScrollViewer Grid.Row="2" Grid.Column="0" Background="Gray">
<StackPanel x:Name="holderpanel" Orientation="Vertical"/>
</ScrollViewer>
I want to put datawrapper into holderpanel from the Main Window's code behind programmatically.
If there's control in the datawrapper, dadawrapper is inserted into holder panel.
However, in case of empty StackPanel, never inserted.
How to do this?
To help you clarify your question, I'll provide an example of exactly what you asked for:
<Grid>
<ScrollViewer Grid.Row="2" Grid.Column="0" Background="Gray">
<StackPanel x:Name="holderpanel" Orientation="Vertical"/>
</ScrollViewer>
<Grid>
<StackPanel x:Name="datawrapper" Orientation="Horizontal" Background="Yellow">
<TextBlock Text="Test"/>
</StackPanel>
</Grid>
</Grid>
codebehind (for this example, I added to Loaded event handler, but it could be used elsewhere):
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
if (datawrapper.Children.Count > 0)
{
var grid = datawrapper.Parent as Grid;
grid.Children.Remove(datawrapper);
holderpanel.Children.Add(datawrapper);
}
}
The datawrapper should be separated user control and empty like following.
<Grid>
<StackPanel x:Name="datawrapper" Orientation="Horizontal" Background="Yellow"/>
</Grid>
I will add another user controls into the datawrapper horizontally 5 later. That user control is like following.
<UserControl x:Class="WpfTest.ResultItem"
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:WpfTest"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid x:Name="resultitem">
<Border CornerRadius="5" BorderBrush="#e0e0e0" Background="White" BorderThickness="2" DockPanel.Dock="Top" Margin="10 10 10 15">
<Grid Margin="0 30 0 30" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="Chart#" Width="Auto" Height="30" Margin="5 5 0 5" FontSize="20" VerticalAlignment="Center"></TextBlock>
<TextBlock Grid.Row="1" Grid.Column="0" Text="Patient Name" Width="Auto" Height="Auto" Margin="5 5 0 5" FontSize="20" VerticalAlignment="Center"></TextBlock>
<TextBlock Grid.Row="2" Grid.Column="0" Text="Home Phone#" Width="Auto" Height="Auto" Margin="5 5 0 5" FontSize="20" VerticalAlignment="Center"></TextBlock>
<TextBlock Grid.Row="3" Grid.Column="0" Text="Cell Phone#" Width="Auto" Height="Auto" Margin="5 5 0 5" FontSize="20" VerticalAlignment="Center"></TextBlock>
<TextBlock Grid.Row="4" Grid.Column="0" Text="Patient Type" Width="Auto" Height="Auto" Margin="5 5 0 5" FontSize="20" VerticalAlignment="Center"></TextBlock>
</Grid>
</Border>
</Grid>
If the datawrapper is filled with 5 ResultItems, datawrapper will added into the holderpanel vertically.

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!

Resize Scrollviewer and StackPanel WPF C#

how can I make the scrollviewer resize to the bottom edge of the screen, so as to maximize to resize with the mouse ? The way the code is, when the screen is maximized the scroll bar does not appear and it is not possible to scroll the contents.
My xaml File
<Window x:Class="AppSearch.MainWindow" x:Name="mainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="AppSearch" Height="600" Width="820"
WindowStartupLocation="CenterScreen"
Loaded="Window_Loaded"
StateChanged="mainWindow_StateChanged"
ResizeMode="CanResize"
PreviewKeyDown="mainWindow_PreviewKeyDown">
<Grid ShowGridLines="False">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel x:Name="stkContentLeft"
MinWidth="510"
MinHeight="560"
ScrollViewer.VerticalScrollBarVisibility="Hidden"
LoadCompleted="stkContentLeft_LoadCompleted"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Margin="0,0,05,0" Grid.Column="0"/>
<StackPanel Grid.Column="1" x:Name="stckContentRight" Width="276"
Height="{Binding Parent.ActualHeight, Mode=OneWay, RelativeSource={RelativeSource Self}}"
Orientation="Vertical"
HorizontalAlignment="Right">
<Grid VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<StackPanel Height="auto" Grid.Row="0">
<StackPanel x:Name="help" Width="20" Height="20" HorizontalAlignment="Right" Margin="0,5,10,0">
<Image Source="Imagens/help_icon.png"/>
</StackPanel>
<StackPanel x:Name="stkUcSupervisor" Height="50" Width="276" Margin="0,5,0,0" HorizontalAlignment="Center"/>
<TextBox x:Name="txtSearch"
ToolTip="put your key..."
FontSize="13"
Foreground="Black"
BorderThickness="1"
TextWrapping="Wrap"
Margin="0,5,0,05" Width="270" HorizontalAlignment="Center"/>
</StackPanel>
<ScrollViewer x:Name="scroll"
CanContentScroll="True"
IsDeferredScrollingEnabled="False"
UseLayoutRounding="False"
VerticalScrollBarVisibility="Visible"
VerticalAlignment="Top"
BorderThickness="1"
BorderBrush="Gray"
Margin="0,05,0,0"
Grid.Row="1"
Height="455">
<StackPanel x:Name="stkListOfUserControls"
CanVerticallyScroll="True"
Height="455"
OverridesDefaultStyle="False">
<StackPanel.ScrollOwner>
<ScrollViewer AllowDrop="True" />
</StackPanel.ScrollOwner>
</StackPanel>
</ScrollViewer>
</Grid>
</StackPanel>
<StackPanel x:Name="stkPopUp"
Canvas.Bottom="0"
Canvas.Left="0"
Height="285"
Width="280"
VerticalAlignment="Bottom"/>
</Grid>

Silverlight - TabControl refusing to fill remaining space

At my wits end with trying to get a TabControl and TabItems to fill a NavigationPage/Frame.
I have a MasterPage, with a Frame, that will get swapped out for different Pages, which are comprised of UserControls.
The problem I am having is that the TabControl is cutting off the UserControl and not auto sizing properly. Below is an image and the source for the Pages and Controls.
[Field below Location is cutoff] http://imgur.com/FoDGJyN
MainPage.xaml
<UserControl x:Class="TournamentControls.MainPage"
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:navigation="clr-
namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
xmlns:uriMapper="clr-
namespace:System.Windows.Navigation;assembly=System.Windows.Controls.Navigation"
mc:Ignorable="d"
d:DesignHeight="800" d:DesignWidth="800">
<Grid x:Name="LayoutRoot" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<StackPanel Name="topNavi" Orientation="Horizontal" Grid.Row="0">
<TextBlock Name="TournamentsNavi" Text="Tournaments"
MouseLeftButtonUp="TournamentsNavi_MouseLeftButtonUp" Margin="0,0,20,0"/>
<TextBlock Name="DivisonsNavi" Text="Division"
MouseLeftButtonUp="DivisonsNavi_MouseLeftButtonUp" Margin="0,0,20,0"/>
<TextBlock Name="EventsNavi" Text="Events"
MouseLeftButtonUp="EventsNavi_MouseLeftButtonUp" Margin="0,0,20,0"/>
<TextBlock Name="CompetitorsNavi" Text="Competitors"
MouseLeftButtonUp="CompetitorsNavi_MouseLeftButtonUp" Margin="0,0,20,0"/>
<TextBlock Name="MastersNavi" Text="Masters"
MouseLeftButtonUp="MastersNavi_MouseLeftButtonUp" Margin="0,0,20,0"/>
<TextBlock Name="RefereesNavi" Text="Referees"
MouseLeftButtonUp="RefereesNavi_MouseLeftButtonUp"/>
</StackPanel>
<navigation:Frame x:Name="PageContent" Background="#007A0909" Grid.Row="1"
Navigated="PageContent_Navigated" Navigating="PageContent_Navigating">
<navigation:Frame.UriMapper>
<uriMapper:UriMapper>
<uriMapper:UriMapping Uri="/{pageName}"
MappedUri="/Pages/{pageName}.xaml"/>
</uriMapper:UriMapper>
</navigation:Frame.UriMapper>
</navigation:Frame>
</Grid>
</UserControl>
TournamentsPage.xaml
<navigation:Page x:Class="TournamentControls.Tournaments"
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"
xmlns:navigation="clr-
namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
xmlns:toolkit2="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
xmlns:cc="clr-namespace:TournamentControls.Controls.Tournaments"
d:DesignWidth="640" d:DesignHeight="480" Title="Tournaments Page">
<Grid x:Name="LayoutRoot" Background="White">
<toolkit2:TabControl>
<toolkit2:TabItem x:Name="CreateTab" Header="Create Tournament">
<cc:TournamentsCreateControl/>
</toolkit2:TabItem>
<toolkit2:TabItem x:Name="ModifyTab" Header="Modify Tournament">
<cc:TournamentsModifyControl/>
</toolkit2:TabItem>
</toolkit2:TabControl>
</Grid>
</navigation:Page>
TournamentsCreateControl.xaml
<Grid x:Name="LayoutRoot" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Border Grid.Row="0" Margin="0,4,0,4" Style="{StaticResource TaskGridMenuBarBorderStyle}" Grid.ColumnSpan="2" >
<Grid HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<Border Style="{StaticResource TaskGridMenuBorderStyle}" Margin="0,0,25,0" Padding="10,0" Grid.ColumnSpan="1" HorizontalAlignment="Left">
<StackPanel x:Name="pnlTaskGridToolbar" Orientation="Horizontal">
<!-- save -->
<Button x:Name="SaveButton" Style="{StaticResource ImageButtonStyle}"
Click="SaveButton_Click" ToolTipService.ToolTip="Save BMC Structure" Margin="0,0,5,0" >
<Button.Content>
<StackPanel Orientation="Horizontal">
<Image Source="../../Resources/Icons/Save.png" Margin="0,0,2,0" />
<TextBlock VerticalAlignment="Center">Save Tournament</TextBlock>
</StackPanel>
</Button.Content>
</Button>
</StackPanel>
</Border>
</Grid>
</Border>
<Grid x:Name="ContentGrid" Grid.Row="1" VerticalAlignment="Stretch">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" x:Name="LabelsSP" Orientation="Horizontal" VerticalAlignment="Center" Margin="0,5,0,10">
<TextBlock x:Name="TournamentLbl" Text="Tournament Name:" FontWeight="Bold" Margin="0,0,10,0" VerticalAlignment="Center"/>
<TextBox x:Name="TournamentTbx" Width="100" MaxLength="255"/>
</StackPanel>
<StackPanel Grid.Row="1" x:Name="LocationSP" Orientation="Horizontal" VerticalAlignment="Center" Margin="0,0,0,10">
<TextBlock x:Name="LocationLbl" Text="Location:" FontWeight="Bold" Margin="60,0,12,0" VerticalAlignment="Center"/>
<TextBox x:Name="LocationTbx" Width="100" MaxLength="255"/>
</StackPanel>
<StackPanel Grid.Row="2" x:Name="DateTimeSP" Orientation="Horizontal" VerticalAlignment="Center" Margin="0,0,0,10">
<TextBlock x:Name="DateTimeLbl" Text="Tournament Time:" FontWeight="Bold" Margin="3,0,12,0" VerticalAlignment="Center"/>
<toolkit2:DatePicker x:Name="DateTimePicker"/>
</StackPanel>
<StackPanel x:Name="ButtonSP" Orientation="Horizontal"/>
</Grid>
</Grid>
</Grid>
TournamentsModifyControl.xaml
<Grid x:Name="LayoutRoot" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Border Grid.Row="0" Margin="0,4,0,4" Style="{StaticResource TaskGridMenuBarBorderStyle}" Grid.ColumnSpan="2" >
<Grid HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition/>
</Grid.RowDefinitions>
<Border Style="{StaticResource TaskGridMenuBorderStyle}" Margin="0,0,25,0" Padding="10,0" Grid.ColumnSpan="1" HorizontalAlignment="Left">
<StackPanel x:Name="pnlTaskGridToolbar" Orientation="Horizontal">
<!-- save -->
<Button x:Name="SaveButton" Style="{StaticResource ImageButtonStyle}"
Click="SaveButton_Click" ToolTipService.ToolTip="Save Tournament Changes" Margin="0,0,5,0" >
<Button.Content>
<StackPanel Orientation="Horizontal">
<Image Source="../../Resources/Icons/Save.png" Margin="0,0,2,0" />
<TextBlock VerticalAlignment="Center">Save Tournament Changes</TextBlock>
</StackPanel>
</Button.Content>
</Button>
</StackPanel>
</Border>
</Grid>
</Border>
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" x:Name="TournamentsSelectSP" Orientation="Horizontal" Margin="0,5,0,10">
<TextBlock x:Name="CurrentTournamentsLbl" Text="Current Tournaments:" FontWeight="Bold" VerticalAlignment="Center" Margin="0,0,10,0"/>
<ComboBox x:Name="CurrentTournamentsCbx"/>
</StackPanel>
<StackPanel Grid.Row="1" x:Name="LabelsSP" Orientation="Horizontal" Margin="0,0,0,10">
<TextBlock x:Name="TournamentLbl" Text="Tournament Name:" FontWeight="Bold" Margin="0,0,10,0" VerticalAlignment="Center"/>
<TextBox x:Name="TournamentTbx" Width="100" MaxLength="255"/>
</StackPanel>
<StackPanel Grid.Row="2" x:Name="LocationSP" Orientation="Horizontal" Margin="0,0,0,10">
<TextBlock x:Name="LocationLbl" Text="Location:" FontWeight="Bold" Margin="60,0,12,0" VerticalAlignment="Center"/>
<TextBox x:Name="LocationTbx" Width="100" MaxLength="255"/>
</StackPanel>
<StackPanel Grid.Row="3" x:Name="DateTimeSP" Orientation="Horizontal" Margin="0,0,0,10">
<TextBlock x:Name="DateTimeLbl" Text="Tournament Time:" FontWeight="Bold" Margin="3,0,12,0" VerticalAlignment="Center"/>
<toolkit2:DatePicker x:Name="DateTimePicker"/>
</StackPanel>
</Grid>
</Grid>

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