Combobox not setting width right in stack panel - c#

I am trying to design a form in WPF. So far:
<Window x:Class="OCLMEditor.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:OCLMEditor"
mc:Ignorable="d"
Title="Christian Life and Ministry Editor" Height="517.366" Width="729.7">
<Grid Margin="0,0,0,3">
<StackPanel Grid.Row="0" Grid.ColumnSpan="4" VerticalAlignment="Top" >
<Menu x:Name="menuOCLM">
<MenuItem Header="File">
<MenuItem Header="Download Schedule Information"/>
<Separator/>
<MenuItem Header="Export Student Information"/>
<MenuItem Header="Import Student Information"/>
<Separator/>
<MenuItem Header="Page Setup"/>
<MenuItem Header="Print Preview"/>
<Separator/>
<MenuItem Header="Update Google Calendar"/>
<Separator/>
<MenuItem Header="Exit"/>
</MenuItem>
<MenuItem Header="Edit"/>
<MenuItem Header="View"/>
<MenuItem Header="Options"/>
<MenuItem Header="Help"/>
</Menu>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
<Grid.Row>1</Grid.Row>
<StackPanel Margin="5 0 0 0" HorizontalAlignment="Stretch">
<Grid.Column>0</Grid.Column>
<Grid.Row>1</Grid.Row>
<Grid.RowSpan>2</Grid.RowSpan>
<Label>Week of Meeting:</Label>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
<ComboBox>
<ComboBoxItem>
<StackPanel Orientation="Horizontal">
<Image Source="special_event.png"></Image>
<Label>Date 1</Label>
</StackPanel>
</ComboBoxItem>
<ComboBoxItem>
<StackPanel Orientation="Horizontal">
<Image Source="special_event.png"></Image>
<Label>Date 2</Label>
</StackPanel>
</ComboBoxItem>
<ComboBoxItem>
<StackPanel Orientation="Horizontal">
<Image Source="special_event.png"></Image>
<Label>Date 3</Label>
</StackPanel>
</ComboBoxItem>
</ComboBox>
<Image HorizontalAlignment="Right" Source="event_time.png"></Image>
</StackPanel>
<Label>Note:</Label>
<ComboBox IsEditable="True">
<ComboBoxItem>Sample Text</ComboBoxItem>
</ComboBox>
<Label>Bible Reading for Week:</Label>
<TextBox>PSALMS 60-68</TextBox>
<Label>Opening Song:</Label>
<ComboBox>
<ComboBoxItem>Song 1</ComboBoxItem>
<ComboBoxItem>Song 2</ComboBoxItem>
<ComboBoxItem>Song 3</ComboBoxItem>
</ComboBox>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="10 0 0 0">
<Label>Chairman:</Label>
<ComboBox></ComboBox>
<Label>Auxiliary Counsellor 1:</Label>
<ComboBox></ComboBox>
<Label>Auxiliary Counsellor 2:</Label>
<ComboBox></ComboBox>
<Label>Prayer:</Label>
<ComboBox></ComboBox>
</StackPanel>
</StackPanel>
<GridSplitter Grid.Column="1" Background="Yellow" HorizontalAlignment="Left" Width="5"></GridSplitter>
<WebBrowser x:Name="htmlView" VerticalAlignment="Stretch">
<Grid.Column>1</Grid.Column>
<Grid.Row>1</Grid.Row>
<Grid.RowSpan>4</Grid.RowSpan>
</WebBrowser>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="25*"/>
<ColumnDefinition Width="50*"/>
<ColumnDefinition Width="25*"/>
</Grid.ColumnDefinitions>
</Grid>
</Window>
The problem:
There are a few issues but I will limit this question to 1. The combo is not wide enough. The combo and image should fill the width.

StackPanel in designed to grow infinitely and it will not fit for what you need. Grid will be good choice.
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<ComboBox>
<ComboBoxItem>
<StackPanel Orientation="Horizontal">
<Image Source="special_event.png"></Image>
<Label>Date 1</Label>
</StackPanel>
</ComboBoxItem>
<ComboBoxItem>
<StackPanel Orientation="Horizontal">
<Image Source="special_event.png"></Image>
<Label>Date 2</Label>
</StackPanel>
</ComboBoxItem>
<ComboBoxItem>
<StackPanel Orientation="Horizontal">
<Image Source="special_event.png"></Image>
<Label>Date 3</Label>
</StackPanel>
</ComboBoxItem>
</ComboBox>
<Image Grid.Column="1" HorizontalAlignment="Right" Source="event_time.png"></Image>
</Grid>

Related

Go to location when click button on Bing maps Wpf

I want when click button then go to Location reserved or select in combobox. This example https://learn.microsoft.com/en-us/previous-versions/bing/wpf-control/hh830432(v=msdn.10) but i don't know code behind for ChangeMapView_Click or full code for xaml below. Another know code behind, maybe share with me. Thank you!
<Window x:Class="WPFTestApplication.SwitchMapViews"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:m="clr-namespace:Microsoft.Maps.MapControl.WPF;assembly=Microsoft.Maps.MapControl.WPF"
Width="1024" Height="768">
<Grid x:Name="LayoutRoot" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="40" />
<RowDefinition Height="20" />
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<m:Map x:Name="myMap" CredentialsProvider="<strong>INSERT_YOUR_BING_MAPS_KEY</strong>"
Grid.Column="0" Grid.Row="0" Grid.RowSpan="3" Padding="5"
Center="39.3683,-95.2734,0.0000" ZoomLevel="4.000" AnimationLevel="None" Mode="AerialWithLabels"/>
<StackPanel Orientation="Horizontal" Opacity="0.7" Grid.Column="0" Grid.Row="1" HorizontalAlignment="Center">
<Button x:Name="btnNorthAmerica" Click="ChangeMapView_Click" Tag="39.3683,-95.2734,0.0000 4.0000"
Margin="5">
<TextBlock>North America</TextBlock>
</Button>
<Button x:Name="btnNewYork" Click="ChangeMapView_Click" Tag="40.7199,-74.0030,0.0000 12.0000" Margin="5">
<TextBlock>New York</TextBlock>
</Button>
<Button x:Name="btnSanFrancisco" Click="ChangeMapView_Click" Tag="37.6801,-122.3395,0.0000 11.0000" Margin="5">
<TextBlock>San Francisco</TextBlock>
</Button>
<Button x:Name="btnVancouver" Click="ChangeMapView_Click" Tag="49.2765,-123.1030,0.0000 14.0000" Margin="5">
<TextBlock>Vancouver</TextBlock>
</Button>
<ComboBox SelectionChanged="AnimationLevel_SelectionChanged" SelectedIndex="1" Margin="10" Height="20">
<ComboBoxItem Content="None" />
<ComboBoxItem Content="Full" />
</ComboBox>
</StackPanel>
<StackPanel Orientation="Horizontal" Opacity="0.9" Grid.Column="0" Grid.Row="2" HorizontalAlignment="Center">
</StackPanel>
<StackPanel Orientation="Horizontal" Opacity="0.9" Grid.Column="0" Grid.Row="3" HorizontalAlignment="Center">
<TextBlock Text="Latitude: " Padding="5" Foreground="White"/>
<TextBox x:Name="txtLatitude" Text="" IsReadOnly="True" Background="LightGray"/>
<TextBlock Text="Longitude: " Padding="5" Foreground="White" />
<TextBox x:Name="txtLongitude" Text="" IsReadOnly="True" Background="LightGray"/>
</StackPanel>
</Grid>

ItemsControl inside wrappanel not using all available space

I have many elements inside an itemscontrol. This itemscontrol is inside a scrollviewer which is parented by a Wrappanel. With or without this scrollviewer, the elements will stack below eachother and never use all the available space. What am i doing wrong? The wrappanel is inside a grid.
<TabItem Header="Game Sessions">
<Grid Margin="4,5,4,0">
<WrapPanel HorizontalAlignment="Stretch" Name="sessionsWrapPanel">
<Grid>
<ScrollViewer>
<Grid>
<ItemsControl Name="listVideosSessions">
<ItemsControl.ItemTemplate>
<DataTemplate>
<materialDesign:Card Width="200" Margin="5,5,5,5">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="140" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Image Source="{Binding sessionVideoThumbnail}" Height="140" Width="196" Stretch="UniformToFill" />
<Button Grid.Row="0" Style="{StaticResource MaterialDesignFloatingActionMiniAccentButton}" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0 0 16 -20">
<materialDesign:PackIcon Kind="Bike" />
</Button>
<StackPanel Grid.Row="1" Margin="8 24 8 0">
<TextBlock FontWeight="Bold">
<Run Text="{Binding sessionsVideoRecordDate}" />
</TextBlock>
<TextBlock TextWrapping="Wrap" VerticalAlignment="Center">
<Run Text="{Binding sessionsVideoRecordtime}" />
</TextBlock>
</StackPanel>
<StackPanel HorizontalAlignment="Right" Grid.Row="2" Orientation="Horizontal" Margin="8">
<Button Style="{StaticResource MaterialDesignToolButton}" Width="30" Padding="2 0 2 0" materialDesign:RippleAssist.IsCentered="True">
<materialDesign:PackIcon Kind="ShareVariant" />
</Button>
<Button Style="{StaticResource MaterialDesignToolButton}" Width="30" Padding="2 0 2 0" materialDesign:RippleAssist.IsCentered="True">
<materialDesign:PackIcon Kind="Heart" />
</Button>
<materialDesign:PopupBox Style="{StaticResource MaterialDesignToolPopupBox}" Padding="2 0 2 0">
<StackPanel>
<Button Content="More" />
<Button Content="Options" />
</StackPanel>
</materialDesign:PopupBox>
</StackPanel>
</Grid>
</materialDesign:Card>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</ScrollViewer>
</Grid>
</WrapPanel>
</Grid>
</TabItem>
It's not really clear what you are trying to achieve, but a scrollable ItemsControl that uses a WrapPanel for the layout of its items, should look like this:
<ItemsControl ItemsSource="{Binding ...}">
<ItemsControl.Template>
<ControlTemplate TargetType="ItemsControl">
<ScrollViewer
HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto">
<ItemsPresenter/>
</ScrollViewer>
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
...
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>

XAML outsourcing datatemplate with events in APP.xaml

I'm having a working datatemplate for a ListView with ItemTemplate
<ListView ItemTemplate="{StaticResource MYTEMPLATE}"
HorizontalAlignment="Center"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ContinuumNavigationTransitionInfo.IsEntranceElement="True">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel VerticalAlignment="Bottom"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
The Template looks like that:
<DataTemplate x:Key="GlobalBox">
<Border Background="#FFFFFFFF" Margin="10 0 0 5" CornerRadius="2 2 15 2">
<Grid Width="380">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Tag="{Binding ID}" Name="ProfileInfo" Tapped="Profile_Tapped" Orientation="Horizontal" Margin="15 15 15 0">
<Grid Width="360" Margin="0 0 0 10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="75"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="50"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Border Grid.Column="0" Height="45" Width="45" CornerRadius="5">
<Border.Background>
<ImageBrush ImageSource="{Binding ImagePath}" Stretch="UniformToFill"/>
</Border.Background>
</Border>
<StackPanel Grid.Column="1" Orientation="Vertical" Margin="0 5 0 0">
<TextBlock Text="{Binding Name}" Foreground="Black" FontSize="18" FontWeight="Bold"></TextBlock>
<TextBlock Text="{Binding Handle}" Foreground="DarkGray" FontSize="12"/>
</StackPanel>
<Image Grid.Column="2" Source="Assets/ActionIcons/logo_blue_32.png" Width="32" VerticalAlignment="Top"></Image>
</Grid>
</StackPanel>
<StackPanel Grid.Row="1" Margin="14.5,0,0,0" Height="Auto">
<StackPanel Name="TweetContent" Tag="{Binding ID}" Margin="15 0 15 0" Tapped="Content_Tapped">
<TextBlock Text ="{Binding Content}" TextWrapping="Wrap" Foreground="Black" FontSize="14" Margin="0 0 0 10"/>
<ItemsControl ItemsSource="{Binding ContentImages}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Image Source="{Binding }" MaxWidth="350" Margin="0 0 0 5" HorizontalAlignment="Center"></Image>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<TextBlock Foreground="DarkGray" Text="{Binding DateSend}" FontSize="10"></TextBlock>
</StackPanel>
<StackPanel Name="ActionButtons">
<Grid Tag="{Binding ID}" Width="380" Height="25" Margin="0 0 0 10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button Grid.Column="0" HorizontalAlignment="Center" Margin="20 0 0 0" Style="{StaticResource replyActionButton}" Tapped="Reply_Tapped"></Button>
<ToggleButton Grid.Column="2" HorizontalAlignment="Center"
Style="{StaticResource retweetActionButton}"
Tapped="Retweet_Tapped"></ToggleButton>
<TextBlock Grid.Column="3" HorizontalAlignment="Left" Margin="-15 0 0 0" VerticalAlignment="Center" Text="{Binding RetweetCount}" Foreground="DarkGray"/>
<ToggleButton Grid.Column="4" HorizontalAlignment="Center"
Style="{StaticResource likeActionButton}"
IsChecked="{Binding LikeState}"
Tapped="Favourite_Tapped"></ToggleButton>
<TextBlock Grid.Column="5" HorizontalAlignment="Left" Margin="-15 0 0 0" VerticalAlignment="Center" Text="{Binding LikeCount}" Foreground="DarkGray"/>
</Grid>
</StackPanel>
</StackPanel>
</Grid>
</Border>
</DataTemplate>
And now when I put the template in the app.xaml file I am getting the following compile error
Events cannot be set in the Application class XAML file
This makes sense for me, but how can I do it anyway? Can I pass the different events like a variable or something into the datatemplate?
//UPDATE - SOLUTION WAY2 using the USERCONTROL:
I've made a UserControl out of the code above and implemented it in the ListView.
<ListView Grid.Row="1" Margin="0 0 0 5"
x:Name = "standardBox"
HorizontalAlignment="Center"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ContinuumNavigationTransitionInfo.IsEntranceElement="True">
<ListView.ItemTemplate>
<DataTemplate>
<local:UCGlobal></local:UCGlobal>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel VerticalAlignment="Bottom"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
You could use a few alternatives:
Use the command property of the buttons inside your templates (take care that your DataContext is set correct, to avoid binding errors):
<DataTemplate x:Key="MyTemplate">
<StackPanel>
<Button x:Name="button1" Content="Button1" Command="{Binding Btn1Command}" CommandParameter="{Binding ElementName=button1}"/>
<Button x:Name="button2" Content="Button2" Command="{Binding Btn2Command}" CommandParameter="{Binding ElementName=button2}"/>
<Button x:Name="button3" Content="Button3" Command="{Binding Btn3Command}" CommandParameter="{Binding ElementName=button3}"/>
</StackPanel>
</DataTemplate>
If it´s another type of event that won't call the command you could use InvokeCommandAction which will be handled same as shown in the next example.
Use a trigger like CallMethodAction (same as above. The DataContext is the place where the method will be searched for.):
<DataTemplate x:Key="MyTemplate">
<StackPanel>
<Button x:Name="button1" Content="Button1" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="Tapped">
<ei:CallMethodAction MethodName="button1_Tapped"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>...
Write a small UserControl as the base for your DataTemplate:
XAML:
<UserControl x:Class="ThreeBtnUserCtrl"
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:DataTemplateIssue"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<StackPanel>
<Button x:Name="button1" Content="Button" Click="button1_Click"/>
<Button x:Name="button2" Content="Button" Click="button2_Click"/>
<Button x:Name="button3" Content="Button" Click="button3_Click"/>
</StackPanel>
</UserControl>
Code behind:
public partial class ThreeBtnUserCtrl : UserControl
{
public ThreeBtnUserCtrl()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
//...some code only controlling view related stuff of your UserCtrl
}
private void button2_Click(object sender, RoutedEventArgs e)
{
//...some code only controlling view related stuff of your UserCtrl
}
private void button3_Click(object sender, RoutedEventArgs e)
{
//...some code only controlling view related stuff of your UserCtrl
}
}
Use it inside your DataTemplate:
<DataTemplate x:Key="MyTemplate">
<Grid>
<local:ThreeBtnUserCtrl/>
</Grid>
</DataTemplate>
You can use a Command and EventTrigger and have it bound to your View Model’s command.
<i:Interaction.Triggers>
<i:EventTrigger EventName="Tapped">
<i:InvokeCommandAction Command="{Binding TappedCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
Or use a small UserControl insted a DataTemplate:
<UserControl... >
<StackPanel>
<Button x:Name="button1" Content="Button" Click="button1_Click"/>
</StackPanel>
</UserControl>
And use it in your app.xaml:
<DataTemplate x:Key="Template">
<Grid>
<local:myUserControl/>
</Grid>
</DataTemplate>
Use Behaviours in stackpanel
<DataTemplate x:Key="GlobalBox">
<Border Background="#FFFFFFFF" Margin="10 0 0 5" CornerRadius="2 2 15 2">
<Grid Width="380">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Tag="{Binding ID}" Name="ProfileInfo" Orientation="Horizontal" Margin="15 15 15 0">
<Grid Width="360" Margin="0 0 0 10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="75"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="50"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Border Grid.Column="0" Height="45" Width="45" CornerRadius="5">
<Border.Background>
<ImageBrush ImageSource="{Binding ImagePath}" Stretch="UniformToFill"/>
</Border.Background>
</Border>
<StackPanel Grid.Column="1" Orientation="Vertical" Margin="0 5 0 0">
<TextBlock Text="{Binding Name}" Foreground="Black" FontSize="18" FontWeight="Bold"></TextBlock>
<TextBlock Text="{Binding Handle}" Foreground="DarkGray" FontSize="12"/>
</StackPanel>
<Image Grid.Column="2" Source="Assets/ActionIcons/logo_blue_32.png" Width="32" VerticalAlignment="Top"></Image>
</Grid>
<interact:Interaction.Behaviors>
<interactcore:EventTriggerBehavior EventName="Tapped" >
<interactcore:InvokeCommandAction Command="{Binding Path=DataContext.Btn1Command}" />
</interactcore:EventTriggerBehavior>
</interact:Interaction.Behaviors>
</StackPanel>
</Grid>
</Border>
</DataTemplate>

Page scrollbar windows 8

my problem is that I have only scrollbar for gridview but don't have scrollbar for entire page. Scrollbar should be at the bottom of the page, horizontal. I tried to add scrollbar to the bottom, but it doesn't appear on the page. I've also posted a link to the picture for better understanding. http://i40.tinypic.com/2rm0389.png Sorry that i have only a link, because i need 10 reputation to post images here, it is so bad.
Thanks in advance.
Here is my code (XAML), not entire page, my scrollbar at the bottom:
<!-- Back button and page title -->
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
<TextBlock x:Name="pageTitle" Text="Профиль" Grid.Column="1" IsHitTestVisible="false" Style="{StaticResource PageHeaderTextStyle}"/>
</Grid>
<Grid Width="Auto" Margin="0,5,0,0" Grid.Row="1"
>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="0*"/>
</Grid.ColumnDefinitions>
<Image Source="{Binding ProfileImage}" Stretch="UniformToFill" HorizontalAlignment="Left" Height="270" Margin="165,46,0,0" VerticalAlignment="Top" Width="225"/>
<TextBlock Text="{Binding Name}" HorizontalAlignment="Left" Margin="165,5,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Height="41" Width="252" FontSize="22" FontWeight="Bold"/>
<GridView x:Name="GridViewToFrinedsPhoto" Margin="461,0,0,0"
ItemsSource="{Binding Mode=TwoWay, Source={StaticResource groupedItemsViewSource}}"
ItemTemplate="{StaticResource MyPhotoItemTemplate}"
SelectionMode="Single"
IsItemClickEnabled="True"
IsSwipeEnabled="false" ItemClick="GridViewToFrinedsPhoto_ItemClick">
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</GridView.ItemsPanel>
<GridView.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<Grid Margin="1,0,0,6">
<Button
x:Name="ColumnBtn"
AutomationProperties.Name="Group Title" AutomationProperties.LabeledBy="{Binding Title}"
Style="{StaticResource TextPrimaryButtonStyle}" Click="Button_Click_1">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Title}" Margin="3,-7,10,10" Style="{StaticResource GroupHeaderTextStyle}" />
<TextBlock Text="{StaticResource ChevronGlyph}" FontFamily="Segoe UI Symbol" Margin="0,-7,0,10" Style="{StaticResource GroupHeaderTextStyle}"/>
</StackPanel>
</Button>
</Grid>
</DataTemplate>
</GroupStyle.HeaderTemplate>
<GroupStyle.Panel>
<ItemsPanelTemplate>
<VariableSizedWrapGrid Orientation="Vertical" Margin="0,0,80,0"/>
</ItemsPanelTemplate>
</GroupStyle.Panel>
</GroupStyle>
</GridView.GroupStyle>
</GridView>
<ScrollBar VerticalAlignment="Bottom" HorizontalAlignment="Center" Width="Auto" RenderTransformOrigin="0.588,-0.824" Visibility="Visible" Margin="0,0,0,603" Orientation="Horizontal" /> -- HERE IS MY SCROLLBAR, DOESN'T WORK :[
</Grid>
</Grid>
My Final code, i hope it helps someone else, I have used scrollviewer and grid container, thanks to Vishal Kaushik from MSDN
<common:LayoutAwarePage
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:VKClient.Views"
xmlns:common="using:VKClient.Common"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:vkControls="using:VKClient.VkControls"
xmlns:Controls="using:Callisto.Controls"
x:Name="pageRoot"
x:Class="VKClient.Views.ProfileViewPage"
DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Mode=Self}}"
mc:Ignorable="d">
<common:LayoutAwarePage.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="../Resources/MyStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
<CollectionViewSource x:Name="groupedItemsViewSource"
Source="{Binding Items, Mode=TwoWay}"
IsSourceGrouped="True"
ItemsPath="Items"/>
</ResourceDictionary>
</common:LayoutAwarePage.Resources>
<!--
This grid acts as a root panel for the page that defines two rows:
* Row 0 contains the back button and page title
* Row 1 contains the rest of the page layout
-->
<common:LayoutAwarePage.BottomAppBar>
<AppBar x:Name="BottomAppBar2" Padding="10,0,10,0">
<Grid>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<Button x:Name="MyProfileButton" Style="{StaticResource MyProfileAppBarButtonStyle}" Click="MyProfileClicked" />
<Button x:Name="MyFriendsButton" Style="{StaticResource MyFriendsAppBarButtonStyle}" Click="MyFriendsClicked"/>
<Button x:Name="MyPhotoButton" Style="{StaticResource MyPhotoAppBarButtonStyle}" Click="MyPhotoClicked" />
<Button x:Name="MyVideosButton" Style="{StaticResource MyVideoesAppBarButtonStyle}" Click="MyVideoesClicked"/>
<Button x:Name="MyAudioButton" Style="{StaticResource MyAudioAppBarButtonStyle}" Click="MyAudioClicked"/>
<Button x:Name="MyGroupsButton" Style="{StaticResource MyGroupsAppBarButtonStyle}" Click="MyGroupsClicked"/>
<!-- <Button x:Name="MyMessagesButton" Style="{StaticResource MyMessagesAppBarButtonStyle}" Click="MyMessagesClicked"/>
<Button x:Name="MyNewsButton" Style="{StaticResource MyNewsAppBarButtonStyle}" Click="MyNewsClicked"
/> -->
</StackPanel>
</Grid>
</AppBar>
</common:LayoutAwarePage.BottomAppBar>
<Grid Style="{StaticResource LayoutRootStyle}" Background="{StaticResource AccentBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="140"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!-- Horizontal scrolling grid used in most view states -->
<!-- Vertical scrolling list only used when snapped -->
<!-- Back button and page title -->
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
<TextBlock x:Name="pageTitle" Text="Профиль" Grid.Column="1" IsHitTestVisible="false" Style="{StaticResource PageHeaderTextStyle}"/>
</Grid>
<Grid Width="Auto" Margin="0,5,0,0" Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="0*"/>
</Grid.ColumnDefinitions>
<ScrollViewer HorizontalScrollMode="Auto" HorizontalScrollBarVisibility="Auto"
VerticalScrollMode="Disabled" VerticalScrollBarVisibility="Disabled">
<Grid Width="Auto">
<Controls:LiveTile HorizontalAlignment="Left" Margin="20,101,0,0" VerticalAlignment="Top" Width="109" Height="137" Background="LightGreen">
<Controls:LiveTile.ItemTemplate>
<DataTemplate>
<Grid Margin="5">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Button Style="{StaticResource MyGroupsAppBarButtonStyle}" Margin="0,0,0,41" Grid.RowSpan="2"/>
<HyperlinkButton
HorizontalAlignment="Right"
Foreground="LightGray"
Click="GroupClicked" Height="129" Grid.RowSpan="2" Width="90" />
</Grid>
</DataTemplate>
</Controls:LiveTile.ItemTemplate>
</Controls:LiveTile>
<Controls:LiveTile HorizontalAlignment="Left" Margin="20,273,0,0" VerticalAlignment="Top" Width="109" Height="151" Background="Violet">
<Controls:LiveTile.ItemTemplate>
<DataTemplate>
<Grid Margin="5">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Button Style="{StaticResource MyAudioAppBarButtonStyle}" Margin="0,0,0,41" Grid.RowSpan="2"/>
<HyperlinkButton
HorizontalAlignment="Right"
Foreground="LightGray"
FontSize="9" FontWeight="Bold" Click="ProfileAudios" Height="139" Grid.RowSpan="2" Width="99" />
</Grid>
</DataTemplate>
</Controls:LiveTile.ItemTemplate>
</Controls:LiveTile>
<Image Source="{Binding ProfileImage}" Stretch="UniformToFill" HorizontalAlignment="Left" VerticalAlignment="Top" Height="270" Margin="165,46,0,0" Width="225"/>
<TextBlock Text="{Binding Name}" Margin="165,5,0,577" TextWrapping="Wrap" HorizontalAlignment="Left" Height="41" Width="252" FontSize="22" FontWeight="Bold"/>
<GridView x:Name="GridViewToFrinedsPhoto" Margin="461,0,0,0"
ItemsSource="{Binding Mode=TwoWay, Source={StaticResource groupedItemsViewSource}}"
ItemTemplate="{StaticResource MyPhotoItemTemplate}"
SelectionMode="Single"
IsItemClickEnabled="True"
IsSwipeEnabled="false" ItemClick="GridViewToFrinedsPhoto_ItemClick">
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</GridView.ItemsPanel>
<GridView.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<Grid Margin="1,0,0,6">
<Button
x:Name="ColumnBtn"
AutomationProperties.Name="Group Title" AutomationProperties.LabeledBy="{Binding Title}"
Style="{StaticResource TextPrimaryButtonStyle}" Click="Button_Click_1">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Title}" Margin="3,-7,10,10" Style="{StaticResource GroupHeaderTextStyle}" />
<TextBlock Text="{StaticResource ChevronGlyph}" FontFamily="Segoe UI Symbol" Margin="0,-7,0,10" Style="{StaticResource GroupHeaderTextStyle}"/>
</StackPanel>
</Button>
</Grid>
</DataTemplate>
</GroupStyle.HeaderTemplate>
<GroupStyle.Panel>
<ItemsPanelTemplate>
<VariableSizedWrapGrid Orientation="Vertical" Margin="0,0,80,0"/>
</ItemsPanelTemplate>
</GroupStyle.Panel>
</GroupStyle>
</GridView.GroupStyle>
</GridView>
</Grid>
</ScrollViewer>
</Grid>
</Grid>

wpf C# Hide / Show Controls in Resource File

I am playing around with WPF for the first time and i am tring to show / hide group objects on a test toolbar based on a toggle button.
The toolbar is created via a template in a resource dictionary and i cannot figure out how to get this working as it seems alot more of an issue compared to winforms.
Out of all the examples i have found they all seem to function if the item is not templated is there any way i can acheive this.
my code so far is below and the point of failure is on the login togglebutton as i have x:name reference and apparently i cannot do this as its part of a resource dictionary, so i am pretty stumped...
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="clr-namespace:wpfApplication1">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/wpfApplication1;component/Resources/Styles/Shared.xaml"/>
<ResourceDictionary Source="pack://application:,,,/wpfApplication1;component/Resources/Styles/ToolBar.xaml"/>
</ResourceDictionary.MergedDictionaries>
<ToolBar x:Key="MyToolbar" Height="120">
<ToolBar.Resources>
<BooleanToVisibilityConverter x:Key="boolToVis"/>
</ToolBar.Resources>
<GroupBox x:Name="tBtn" Header="Login" Style="{StaticResource ToolbarGroup}" Margin="5,3,3,3">
<StackPanel Grid.Row="1" Orientation="Horizontal">
<!--Login-->
<ToggleButton Margin="3" Width="55" Style="{StaticResource ToolBarButtonBaseStyle}"
HorizontalContentAlignment="Center""
CommandTarget="{Binding ElementName=MyTestApp}">
<ToggleButton.Content>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="4*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<Image Source="pack://application:,,,/wpfApplication1;component/Resources/Images/Login.png" Width="45"/>
<TextBlock Grid.Row="1" Text="New" VerticalAlignment="Bottom" HorizontalAlignment="Center"/>
</Grid>
</ToggleButton.Content>
</ToggleButton>
</StackPanel>
</GroupBox>
<GroupBox Visibility="{Binding Path=IsChecked, ElementName=tBtn, Converter={StaticResource boolToVis}}" Header="File" Style="{StaticResource ToolbarGroup}" Margin="5,3,3,3">
<StackPanel Grid.Row="1" Orientation="Horizontal">
<!--File-->
<Button Margin="3" Width="55" Style="{StaticResource ToolBarButtonBaseStyle}"
HorizontalContentAlignment="Center"
Command="{x:Static ApplicationCommands.New}"
CommandTarget="{Binding ElementName=MyTestApp}">
<Button.Content>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="4*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<Image Source="pack://application:,,,/wpfApplication1;component/Resources/Images/GenericDocument.png" Width="45"/>
<TextBlock Grid.Row="1" Text="New" VerticalAlignment="Bottom" HorizontalAlignment="Center"/>
</Grid>
</Button.Content>
</Button>
<StackPanel Orientation="Vertical" Margin="0,2,0,2">
<Button Margin="1" Padding="2" HorizontalContentAlignment="Left"
Style="{StaticResource ToolBarButtonBaseStyle}"
Command="{x:Static ApplicationCommands.Open}"
CommandTarget="{Binding ElementName=MyTestApp}">
<Button.Content>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Image Source="pack://application:,,,/wpfApplication1;component/Resources/Images/OpenFolder.png" Width="16"/>
<TextBlock Margin="3,0,3,0" Text="Open" VerticalAlignment="Center" Grid.Column="1"/>
</Grid>
</Button.Content>
</Button>
<Button Margin="1" Padding="2" HorizontalContentAlignment="Left"
Style="{StaticResource ToolBarButtonBaseStyle}"
Command="{x:Static ApplicationCommands.Save}"
CommandTarget="{Binding ElementName=MyTestApp}">
<Button.Content>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Image Source="pack://application:,,,/wpfApplication1;component/Resources/Images/Save.png" Width="16"/>
<TextBlock Margin="3,0,3,0" Text="Save" VerticalAlignment="Center" Grid.Column="1"/>
</Grid>
</Button.Content>
</Button>
<Button Margin="1" Padding="2" HorizontalContentAlignment="Left"
Style="{StaticResource ToolBarButtonBaseStyle}"
Command="{x:Static ApplicationCommands.Print}"
CommandTarget="{Binding ElementName=MyTestApp}">
<Button.Content>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Image Source="pack://application:,,,/wpfApplication1;component/Resources/Images/Print.png" Width="16"/>
<TextBlock Margin="3,0,3,0" Text="Print" VerticalAlignment="Center" Grid.Column="1"/>
</Grid>
</Button.Content>
</Button>
</StackPanel>
</StackPanel>
</GroupBox>
</ToolBar>
</ResourceDictionary>
Many thanks in advance for any assistance
now your GroupBox is called "tBtn" but that should be your ToggleButton. (as you are refering to its property IsChecked)
Try to name your ToggleButton tBtn and retry

Categories

Resources