How can i centred a popup on my window in XAML? - c#

i want to have a centred popup notifications on my window ( Height="400" Width="500"). See the xaml code below. Is it possible to center it only with xaml (without the code behind)?
</Grid>
<TextBlock Text="TEXT" Grid.Row="1" Grid.Column="0" Grid.RowSpan="2" Grid.ColumnSpan="3" FontSize="200" FontWeight="Bold" HorizontalAlignment="Center"/>
<Grid Grid.Row="1" Grid.Column="1">
<Popup x:Name="PopupName" Grid.ColumnSpan="2" IsOpen="{Binding ElementName=ToggleButton,Path=IsChecked}" StaysOpen="False" Placement="Absolute"
AllowsTransparency="True" PopupAnimation="None" Focusable="False" HorizontalAlignment="Center" VerticalAlignment="Center">
<Grid Height="400" Width="500">
<Rectangle Fill="Silver" Opacity="0.5" Panel.ZIndex="1" Height="400" Width="500"/>
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center" Panel.ZIndex="2" Height="150" Width="150">
<ListBox Height="Auto" HorizontalAlignment="Center" >
<Label Content="Red" Background="Red" Margin="5" VerticalAlignment="Top"/>
<Label Content="Green" Background="Green" Margin="5" VerticalAlignment="Center"/>
<Label Content="Yellow" Background="Yellow" Margin="5" VerticalAlignment="Bottom"/>
</ListBox>
</StackPanel>
<ToggleButton Panel.ZIndex="2" Background="Coral" Foreground="White" FontWeight="Bold" Name ="Button" Width="80" Height="30" HorizontalAlignment="Center" Margin="5,170,5,5" Content="Close" Click="Button_OnClick"/>
</Grid>
</Popup>
</Grid>
Another option was to use Placement ="AbsolutePoint" with Horizon-/Verticaloffset but it seems like a bit weird :D
Any suggestion? Thx ;)

This should center the Popup in the parent window:
<Popup ...
Placement="Center"
PlacementTarget="{Binding RelativeSource={RelativeSource AncestorType=Window}}" />

Related

LocalizedStrings not recognized in VS2015 Universal Project

I'm trying to convert a WP8 projet to Universal Apps. I'experiecing a strange error regarding LocalizedStrings.
I use Multilingual App Toolkit to manage translations. I've updated to the latest version (4.0) which says it supports Universal apps.
The thing is it gives me this error in App.xaml: The name "LocalizedStrings" does not exist in the namespace "using:StayfilmUniversalApp".
And it is complaining on the MainPage.xaml too but not in other pages...
In MainPage.xaml it says that The type LocalizedStrings was not found. underlined in color blue the whole DataTemplate block that has a component which uses LocalizedStrings, for eg.:
<DataTemplate x:Key="TIT_WhatsNew">
<Grid Width="250" Height="52" Margin="0" HorizontalAlignment="Left">
<Rectangle Fill="White" HorizontalAlignment="Left" Height="3" Margin="0" VerticalAlignment="Top" Width="250" />
<TextBlock HorizontalAlignment="Center" TextWrapping="Wrap" Text="{Binding LocalizedResources.WHATSNEW, Mode=OneWay, Source={StaticResource LocalizedStrings}}" VerticalAlignment="Center" FontSize="21.333" FontStretch="ExtraCondensed" FontFamily="/Assets/Fonts/Frontage-regular.otf#Frontage Regular" />
<Rectangle Fill="White" HorizontalAlignment="Left" Height="3" Margin="0" VerticalAlignment="Bottom" Width="250" />
</Grid>
</DataTemplate>
here is my App.xaml:
<Application
x:Class="StayfilmUniversalApp.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:StayfilmUniversalApp"
RequestedTheme="Light">
<Application.Resources>
<ResourceDictionary>
<!--<local:LocalizedStrings x:Key="LocalizedStrings"/>-->
<local:LocalizedStrings xmlns:local="using:StayfilmUniversalApp" x:Key="LocalizedStrings" />
<Color x:Key="PhoneDisabledColor">#66FFFFFF</Color>
<SolidColorBrush x:Key="PhoneDisabledBrush" Color="{StaticResource PhoneDisabledColor}" />
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Styles\PhoneStyles.xaml" />
</ResourceDictionary.MergedDictionaries>
<!-- Other resources if you have -->
</ResourceDictionary>
</Application.Resources>
and My LocalizedStrings.cs:
using StayfilmUniversalApp.Resources;
namespace StayfilmUniversalApp
{
/// <summary>
/// Provides access to string resources.
/// </summary>
public class LocalizedStrings
{
private static AppResources _localizedResources = new AppResources();
public AppResources LocalizedResources { get { return _localizedResources; } }
}
}
The problem has nothing to do with LocalizedStrings.
I gave up trying to fix the page and decided to recreate it from scratch. Doing so, I found out there may be a VS bug behind and is showing different error. because when I added a DataTemplate (this one below) to a HubSection it gave me this error on the entire DataTemplate block:
Cannot add instance of type 'Windows.UI.Xaml.Setter' to a collection of type 'Windows.UI.Xaml.SetterBaseCollection'.
<DataTemplate x:Key="YOTWDataTemplate">
<ScrollViewer HorizontalAlignment="Left" VerticalAlignment="Top" BorderThickness="0" Height="548">
<StackPanel x:Name="stackYOTW" Margin="0,0,0,100" HorizontalAlignment="Center" VerticalAlignment="Top" Width="420">
<TextBlock TextWrapping="Wrap" Foreground="White" FontFamily="Portable User Interface" Margin="12,0,0,0">
<Run Text="{Binding LocalizedResources.EveryWeek, Mode=OneWay, Source={StaticResource LocalizedStrings}}"/>
<Run FontWeight="Bold" Text="YES!"/>
<LineBreak/>
<Run Text="{Binding LocalizedResources.ChoosenByStayfilm, Mode=OneWay, Source={StaticResource LocalizedStrings}}"/>
<LineBreak/>
<Run Text="{Binding LocalizedResources.ForYouToWatch, Mode=OneWay, Source={StaticResource LocalizedStrings}}"/>
</TextBlock>
<ListBox x:Name="listYOTW" ItemsSource="{Binding listYesMovie}" Foreground="White" Background="{x:Null}" BorderBrush="{x:Null}" ScrollViewer.VerticalScrollBarVisibility="Disabled">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Margin="12,20,0,0" Background="White" Width="420">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="64"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="64*"/>
<RowDefinition Height="119*"/>
<RowDefinition Height="50*"/>
</Grid.RowDefinitions>
<Image Margin="12" Source="{Binding user.photo}" VerticalAlignment="Center" Width="40" Height="40" HorizontalAlignment="Center" Stretch="Fill"/>
<TextBlock x:Name="NAME" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Center" FontFamily="Segoe WP Semibold" Margin="0" Grid.Column="1" Foreground="#FFAF252B" Text="{Binding user.fullName}" FontSize="18.667"/>
<TextBlock x:Name="TIME" HorizontalAlignment="Right" TextWrapping="Wrap" VerticalAlignment="Center" FontFamily="Segoe WP Light" Margin="0,0,14,0" Grid.Column="1" Foreground="#FF787878" Text="{Binding prettyPublicated}" FontSize="17.333" TextAlignment="Right"/>
<Image Grid.ColumnSpan="2" Margin="0,0,0,59" Grid.RowSpan="2" Source="{Binding thumbnailUrl}" Stretch="UniformToFill" Grid.Row="1"/>
<Grid x:Name="TituloFILM" Grid.ColumnSpan="2" Height="50" VerticalAlignment="Top" Grid.Row="1" Background="#CCAF252B">
<TextBlock x:Name="TITLE" HorizontalAlignment="Left" TextWrapping="Wrap" Text="{Binding title}" VerticalAlignment="Center" Foreground="White" FontFamily="Segoe WP Light" FontSize="24" Margin="14,0,0,0"/>
</Grid>
<Grid x:Name="GridYES" Grid.ColumnSpan="2" HorizontalAlignment="Left" Grid.RowSpan="2" VerticalAlignment="Bottom" Width="80" Grid.Row="2" Height="30" Margin="14">
<Canvas x:Name="iconYES" HorizontalAlignment="Right" Height="20" UseLayoutRounding="False" VerticalAlignment="Center" Width="46" Margin="0">
<Canvas x:Name="Layer_1" Height="15.391" Canvas.Left="0.409" Canvas.Top="2.304" Width="45.182">
<Path Data="F1M10.991,0L7.327,5.987 3.619,0 0,0 5.741,8.801 5.741,14.9 8.913,14.9 8.913,8.801 14.61,0z" Fill="#FF9AA7B2" Height="14.9" Canvas.Left="0" Canvas.Top="0.223" Width="14.61"/>
<Path Data="F1M0,14.901L0,0 10.544,0 10.544,2.793 3.172,2.793 3.172,5.943 10.388,5.943 10.388,8.734 3.172,8.734 3.172,12.109 10.544,12.109 10.544,14.901z" Fill="#FF9AA7B2" Height="14.901" Canvas.Left="15.552" Canvas.Top="0.223" Width="10.544"/>
<Path Data="F1M0,13.024L1.72,10.611C2.77,11.706 4.4,12.622 6.457,12.622 8.199,12.622 9.046,11.817 9.046,10.968 9.046,8.332 0.469,10.142 0.469,4.534 0.469,2.055 2.613,0 6.121,0 8.489,0 10.455,0.715 11.929,2.077L10.164,4.4C8.958,3.283 7.349,2.77 5.83,2.77 4.468,2.77 3.708,3.373 3.708,4.267 3.708,6.635 12.263,5.048 12.263,10.611 12.263,13.336 10.32,15.391 6.299,15.391 3.44,15.391 1.384,14.431 0,13.024" Fill="#FF9AA7B2" Height="15.391" Canvas.Left="27.575" Canvas.Top="0" Width="12.263"/>
<Path Data="F1M0.537,10.053L0.067,0 3.485,0 3.039,10.053z M0,13.337C0,12.354 0.805,11.528 1.787,11.528 2.77,11.528 3.598,12.354 3.598,13.337 3.598,14.297 2.77,15.124 1.787,15.124 0.805,15.124 0,14.297 0,13.337" Fill="#FF9AA7B2" Height="15.124" Canvas.Left="41.584" Canvas.Top="0.223" Width="3.598"/>
</Canvas>
</Canvas>
<TextBlock x:Name="N_YES" HorizontalAlignment="Right" TextWrapping="Wrap" VerticalAlignment="Center" FontFamily="Segoe WP Light" Margin="0,0,59,3" Foreground="#FF35424D" Text="{Binding likeCount}" FontSize="20" TextAlignment="Right"/>
</Grid>
<Grid x:Name="GridCOMENT" Grid.ColumnSpan="2" HorizontalAlignment="Center" VerticalAlignment="Bottom" Width="70" Grid.Row="2" Height="30" Margin="14">
<Canvas x:Name="iconCOMENT" HorizontalAlignment="Right" Height="26" UseLayoutRounding="False" VerticalAlignment="Center" Width="28" Margin="0,2,0,0">
<Canvas x:Name="Layer_4" Height="22.194" Canvas.Left="2.697" Canvas.Top="1.903" Width="22.605">
<Path Data="M23.106,0.5L0.5,0.5 0.5,16.001 6.216,16.001 3.852,22.694 13.176,16.001 23.106,16.001z" Height="24.028" Canvas.Left="-0.5" Stroke="#FF9BA8B3" Canvas.Top="-0.5" Width="23.605"/>
</Canvas>
</Canvas>
<TextBlock x:Name="N_YES1" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Center" FontFamily="Segoe WP Light" Margin="0,-3,0,0" Foreground="#FF35424D" Text="{Binding commentCount}" FontSize="20" TextAlignment="Right"/>
</Grid>
<Grid x:Name="GridVIEW" Grid.ColumnSpan="2" HorizontalAlignment="Right" VerticalAlignment="Bottom" Width="70" Grid.Row="2" Height="30" Margin="14">
<Canvas x:Name="iconVIEW" HorizontalAlignment="Right" Height="26" UseLayoutRounding="False" VerticalAlignment="Center" Width="36">
<Canvas x:Name="Layer_2" Height="18" Canvas.Left="2.113" Canvas.Top="4" Width="31.145">
<Path Data="M31.723,9.5C28.609,4.125 22.809,0.5 16.151,0.5 9.492,0.5 3.692,4.125 0.578,9.5 3.692,14.875 9.492,18.5 16.151,18.5 22.809,18.5 28.609,14.875 31.723,9.5z" Height="19" Canvas.Left="-0.578" Stroke="#FF9BA8B3" Canvas.Top="-0.5" Width="32.301"/>
<Path Data="F1M9.409,4.705C9.409,7.303 7.303,9.41 4.704,9.41 2.106,9.41 0,7.303 0,4.705 0,2.107 2.106,0 4.704,0 7.303,0 9.409,2.107 9.409,4.705" Fill="#FF9BA8B3" Height="9.41" Canvas.Left="10.868" Canvas.Top="4.295" Width="9.409"/>
</Canvas>
</Canvas>
<TextBlock x:Name="N_YES2" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Center" FontFamily="Segoe WP Light" Margin="0,-3,0,0" Foreground="#FF35424D" Text="{Binding viewCount}" FontSize="20" TextAlignment="Right"/>
</Grid>
<Button Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}" Margin="0,50,0,0" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.ColumnSpan="2" Grid.Row="1" Click="Button_Click" Style="{StaticResource ButtonStyle}">
<Canvas x:Name="PLAY" HorizontalAlignment="Center" Height="102" UseLayoutRounding="False" VerticalAlignment="Center" Width="102">
<Canvas x:Name="Layer_3" Height="96" Canvas.Left="2" Canvas.Top="2" Width="96" Margin="0" Background="{StaticResource TransparentBrush}">
<Path Data="F1M0,0L29.333,16.936 0,33.871z" Fill="White" Height="33.871" Canvas.Left="38.26" Canvas.Top="30.998" Width="29.333" Stroke="#26000000"/>
<Ellipse Height="98" Stroke="#26000000" StrokeThickness="5" Width="98" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<Ellipse Height="96" Stroke="White" StrokeThickness="3" Width="96" HorizontalAlignment="Center" VerticalAlignment="Center" Canvas.Left="1" Canvas.Top="1"/>
</Canvas>
</Canvas>
</Button>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBlock x:Name="txt_NoConnection" Foreground="White" TextWrapping="Wrap" Text="{Binding LocalizedResources.NoConnection, Mode=OneWay, Source={StaticResource LocalizedStrings}}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,48,0,0" FontFamily="Segoe WP Light" Visibility="Collapsed"/>
</StackPanel>
</ScrollViewer>
</DataTemplate>
and I say it is a VS bug because I found this: VS bug report

Listbox rows are different each time when scroll

I have listbox control with custom data template. I get the collection from webservice and bind that collection to listbox. When i scroll the list box top to bottom my listbox rows are changed and text are concatenate.
Please see the below images
This is my first screen
when scroll top to bottom once again
please compare two images my rows are changed
<Grid Margin="30,20,0,20" x:Name="MeGrid" Loaded="MeGrid_Loaded" Visibility="{Binding Path=_isMyMessage, Converter={StaticResource BoolToVisibilityConverter}}">
<StackPanel >
<TextBlock HorizontalAlignment="Right" Foreground="#00c0d4" Margin="0,0,100,0" Text="{Binding Path=CreatedDate, Converter={StaticResource TimeSinceConverter}}" />
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Grid Background="#ffffff" Height="auto" Width="auto" MaxWidth="300" MinWidth="50">
<StackPanel Background="White">
<RichTextBox Name="MeRich" Background="White" MaxHeight="600" Foreground="Red"
FontFamily="Segoe UI" Margin="10,0,10,0" VerticalAlignment="Center"
TextWrapping="Wrap" Height="auto"
Width="auto" MinWidth="50"
MaxWidth="300"
local:Properties.Html="{Binding Path=MessageText}">
</RichTextBox>
<readMore:Readmore Source="{Binding Path=MessageText}" Visibility="{Binding ActualHeight,
ElementName=MeRich, Converter={StaticResource ReadMoreVisibilityConverter}}" ></readMore:Readmore>
<!--<TextBlock Margin="10,0,10,0" VerticalAlignment="Center" Foreground="Black" TextWrapping="Wrap" Height="auto" Width="auto" MinWidth="50" MaxWidth="300" Text="{Binding Path=MessageText}"
/>-->
<ListBox ScrollViewer.VerticalScrollBarVisibility="Disabled" ItemsSource="{Binding Path=AttachmentList}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Margin="0,5,0,5">
<Button Click="Image_Download" Loaded="Button_Loaded" Tag="{Binding .}" Width="80" Height="80" >
<Button.Template>
<ControlTemplate TargetType="Button">
<Border HorizontalAlignment="Center" VerticalAlignment="Center" >
<ContentControl Content="{TemplateBinding Content}"/>
</Border>
</ControlTemplate>
</Button.Template>
<Image Source="/Resources/Drawable/c_image.png" Tag="{Binding .}" />
</Button>
<ProgressBar VerticalAlignment="Bottom" IsIndeterminate="true" Visibility="Collapsed" Style="{StaticResource CustomIndeterminateProgressBar}" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</Grid>
<Rectangle Margin="20,0,0,0" VerticalAlignment="Top" RadiusX="50" RadiusY="50" Width="80" Height="80">
<Rectangle.Fill>
<ImageBrush ImageSource="{Binding Path=UserPictureURL}"/>
</Rectangle.Fill>
</Rectangle>
</StackPanel>
</StackPanel>
</Grid>

C# WPF listBox vertical alignment

I have a listBox with a checkbox I want to manage the alignment through setting the vertical alignment.
I have seen several solution here e.g. set verticalContentAlignment or verticalAlignment to top but that didn't work.
I've also seen some setting a style but couldn't manage to make it done.
What I'd like is to know WHY the ONLY element is down there. I can't understand why it's stuck in the middle.
Here's my code:
<ListBox x:Name="lb2Tab3" HorizontalContentAlignment="Stretch" FontSize="{StaticResource BUTTON_FONTSIZE}" Background="{x:Null}" BorderBrush="{x:Null}" Margin="0,0,0.8,0" >
<CheckBox x:Name="cbEasyRunManagesPcDmis" Margin="20" Content="EasyRun Manages PC-DMIS" HorizontalAlignment="Left" VerticalAlignment="Top" Click="cbTouchScreen_Click" />
</ListBox>
thanx for any help
Patrick
--- EDIT ---
As requested by Frisbee here is the complete xaml. Sorry for its length:
<Base:WindowViewBase x:Class="EasyRun.Views.MainView.MainView"
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:Base="clr-namespace:Cannoli.Base;assembly=Cannoli"
xmlns:design="clr-namespace:EasyRun.Views.MainView.Design"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:System="clr-namespace:System;assembly=mscorlib"
xmlns:CannoliBorderlessWindow="clr-namespace:CannoliBorderlessWindow;assembly=Cannoli.BorderlessWindow"
d:DesignWidth="212.32" d:DesignHeight="109.92"
Title="EASY RUN 2.0" Height="600" Width="900" MinWidth="500" FontFamily="/EasyRun2.0;component/Resources/Fonts/#FontAwesome" Icon="/EasyRun2.0;component/Resources/Images/Lightning.png"
>
<d:WindowViewBase.DataContext>
<design:DesignMainViewModel />
</d:WindowViewBase.DataContext>
<i:Interaction.Behaviors>
<CannoliBorderlessWindow:CannoliBorderlessWindowBehavior/>
</i:Interaction.Behaviors>
<!-- RISORSE GLOBALI: VARIABILI -->
<Window.Resources>
<System:Double x:Key="BUTTON_HEIGHT">50</System:Double>
<System:Double x:Key="BUTTON_FONTSIZE">20</System:Double>
</Window.Resources>
<Grid x:Name="MainGrid">
<Grid.Background>
<ImageBrush ImageSource="/EasyRun2.0;component/Resources/Images/gradientWallpaper.jpg"/>
</Grid.Background>
<TextBlock Text="{Binding WelcomeMessage}" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold" Margin="428,128,99.6,228"/>
<StackPanel Orientation="Vertical" VerticalAlignment="Bottom" Margin="0,0,0,20">
</StackPanel>
<TabControl TabStripPlacement="Left" Margin="0,0,-0.4,0" Background="{x:Null}">
<!-- +++++++++++++ TAB1 ++++++++++++ -->
<TabItem Name="tabItem1" HorizontalAlignment="Center" Height="80" FontSize="50" Background="{x:Null}" VerticalAlignment="Top" >
<TabItem.Header>
<StackPanel>
<TextBlock HorizontalAlignment="Center" Text=""/>
<TextBlock Name="tbTab1" HorizontalAlignment="Center" Visibility="Hidden" FontSize="20"/>
</StackPanel>
</TabItem.Header>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Border x:Name="Border1Tab1" BorderBrush="Gainsboro" BorderThickness="5" Width="200" CornerRadius="8,8,3,3" Margin="10,10,10,10.4" >
<ListBox x:Name="lbButtons1" Background="{x:Null}" BorderBrush="{x:Null}" Margin="10,10,10,10" />
</Border>
<Border x:Name="Border2Tab1" BorderBrush="Gainsboro" MinWidth="100" BorderThickness="5" CornerRadius="8,8,3,3" Grid.Column="1" Margin="10,10,9.2,10" />
</Grid>
</TabItem>
<!-- +++++++++++++ TAB2 ++++++++++++ -->
<TabItem Name="tabItem2" HorizontalAlignment="Center" Height="80" FontSize="50">
<TabItem.Header>
<StackPanel>
<TextBlock Text=""/>
<TextBlock Name="tbTab2" Visibility="Hidden" FontSize="20"/>
</StackPanel>
</TabItem.Header>
<TabItem.Background>
<ImageBrush/>
</TabItem.Background>
</TabItem>
<!-- +++++++++++++ TAB3 ++++++++++++ -->
<TabItem Name="tabItem3" HorizontalAlignment="Center" Height="80" FontSize="50" Background="{x:Null}" >
<TabItem.Header>
<StackPanel>
<TextBlock Text="" HorizontalAlignment="Center" />
<TextBlock Name="tbTab3" Visibility="Hidden" FontSize="20"/>
</StackPanel>
</TabItem.Header>
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Border x:Name="Border1Tab3" BorderBrush="Gainsboro" BorderThickness="5" Width="200" CornerRadius="8,8,3,3" Margin="10,10,10,10" >
<ListBox x:Name="lbButtons3" FontSize="{StaticResource BUTTON_FONTSIZE}" HorizontalContentAlignment="Stretch" Background="{x:Null}" BorderBrush="{x:Null}" >
<Button Name="bt1Tab3" Background="{x:Null}" Content="1" Click="Button_Click" />
<Button Name="bt2Tab3" Background="{x:Null}" Height="{StaticResource BUTTON_HEIGHT}" Content="2" Click="Button_Click"/>
<Button Name="bt3Tab3" Background="{x:Null}" Height="{StaticResource BUTTON_HEIGHT}" Content="3" Click="Button_Click"/>
<Button Name="bt4Tab3" Background="{x:Null}" Height="{StaticResource BUTTON_HEIGHT}" Content="4" Click="Button_Click"/>
<Button Name="bt5Tab3" Background="{x:Null}" Height="{StaticResource BUTTON_HEIGHT}" Content="5" Click="Button_Click"/>
<Button Name="bt6Tab3" Background="{x:Null}" Height="{StaticResource BUTTON_HEIGHT}" Content="6" Click="Button_Click"/>
<Button Name="bt7Tab3" Background="{x:Null}" Height="{StaticResource BUTTON_HEIGHT}" Content="7" Click="Button_Click"/>
<Button Name="bt8Tab3" Background="{x:Null}" Height="{StaticResource BUTTON_HEIGHT}" Content="8" Click="Button_Click"/>
</ListBox>
</Border>
<Border x:Name="Border2Tab3" BorderBrush="Gainsboro" MinWidth="100" BorderThickness="5" CornerRadius="8,8,3,3" Grid.Column="1" Margin="10,10,10,10" >
<StackPanel >
<ListBox x:Name="lb1Tab3" HorizontalContentAlignment="Stretch" FontSize="{StaticResource BUTTON_FONTSIZE}" Background="{x:Null}" BorderBrush="{x:Null}" Margin="0,0,0.4,0" d:IsHidden="True" >
<StackPanel Orientation="Horizontal">
<TextBlock x:Name="lbLanguage" Margin="20" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Center" TextAlignment="Center" Grid.Row="1"><Run Text="Language"/></TextBlock>
<ComboBox x:Name="cmbLanguages" Margin="20" HorizontalAlignment="Left" VerticalAlignment="Center" Width="246" Height="35" DropDownClosed="cmbLanguages_DropDownClosed"/>
</StackPanel>
<CheckBox x:Name="cbTouchScreen" Margin="20" Content="Use touch screen" HorizontalAlignment="Left" VerticalAlignment="Top" Click="cbTouchScreen_Click" />
<CheckBox x:Name="cbEnableImages" Margin="20" Content="Enable Images" HorizontalAlignment="Left" VerticalAlignment="Top" />
<StackPanel Name="spImageDimension" Orientation="Horizontal">
<TextBlock x:Name="lbImageDimension" Margin="20" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Center" TextAlignment="Center"><Run Text="Image dimension"/></TextBlock>
<ComboBox x:Name="cmbImageDimension" Margin="20" Text="250 px" HorizontalAlignment="Left" DropDownClosed="cmbImageDimension_DropDownClosed" VerticalAlignment="Center" Width="246" Height="35" IsEditable="True">
<TextBlock ><Run Text="50 px"/></TextBlock>
<TextBlock ><Run Text="100 px"/></TextBlock>
<TextBlock ><Run Text="150 px"/></TextBlock>
<TextBlock ><Run Text="200 px"/></TextBlock>
<TextBlock ><Run Text="250 px"/></TextBlock>
</ComboBox>
</StackPanel>
</ListBox>
<ListBox x:Name="lb2Tab3" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Top" FontSize="{StaticResource BUTTON_FONTSIZE}" Background="{x:Null}" BorderBrush="{x:Null}" Margin="0,0,0.8,0" >
<CheckBox x:Name="cbEasyRunManagesPcDmis" Margin="20" Content="EasyRun Manages PC-DMIS" HorizontalAlignment="Left" VerticalAlignment="Top" Click="cbTouchScreen_Click" />
</ListBox>
<ListBox x:Name="lb3Tab3" HorizontalContentAlignment="Stretch" FontSize="{StaticResource BUTTON_FONTSIZE}" Background="{x:Null}" BorderBrush="{x:Null}" Margin="0,0,0.4,0" />
<ListBox x:Name="lb4Tab3" HorizontalContentAlignment="Stretch" FontSize="{StaticResource BUTTON_FONTSIZE}" Background="{x:Null}" BorderBrush="{x:Null}" Margin="0,0,0.4,0" d:IsHidden="True" >
</ListBox>
<ListBox x:Name="lb5Tab3" HorizontalContentAlignment="Stretch" FontSize="{StaticResource BUTTON_FONTSIZE}" Background="{x:Null}" BorderBrush="{x:Null}" Margin="0,0,0.4,0" d:IsHidden="True" >
</ListBox>
<ListBox x:Name="lb6Tab3" HorizontalContentAlignment="Stretch" FontSize="{StaticResource BUTTON_FONTSIZE}" Background="{x:Null}" BorderBrush="{x:Null}" Margin="0,0,0.4,0" d:IsHidden="True" >
</ListBox>
<ListBox x:Name="lb7Tab3" HorizontalContentAlignment="Stretch" FontSize="{StaticResource BUTTON_FONTSIZE}" Background="{x:Null}" BorderBrush="{x:Null}" Margin="0,0,0.4,0" d:IsHidden="True" >
</ListBox>
<ListBox x:Name="lb8Tab3" HorizontalContentAlignment="Stretch" FontSize="{StaticResource BUTTON_FONTSIZE}" Background="{x:Null}" BorderBrush="{x:Null}" Margin="0,0,0.4,0" d:IsHidden="True" >
</ListBox>
</StackPanel>
</Border>
</Grid>
</TabItem>
</TabControl>
</Grid>
You need to align the ListBox
<ListBox x:Name="lb2Tab3" HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Top"
If that does not work then post more of your XAML
So the problem was related with the fact that there are several listBox one on top of the other. I thought that making them hidden was enough but when I painted the second listBox in black I saw that it was not starting from the top (see image).
So the solution was to set Visibility = Collapsed for all the listbox that are not in use.
Thanks to kirotab for putting me on the right path. Not sure if I can vote your comment.

Togglebutton content change in image in WPF

I have code in wpf which use ToggleButton.
<Grid>
<ToggleButton x:Name="pinButton" VerticalAlignment="Center" Width="auto" MaxWidth="26" Height="26"
Background="{DynamicResource MyBorderBlueGradientBrush}" Focusable="False"
DockPanel.Dock="Right" BorderThickness="0"
OverridesDefaultStyle="False" BorderBrush="{DynamicResource MyBorderBlueGradientBrush}" FontFamily="Webdings">
<Label x:Name="Pinback" Background="{DynamicResource MyBorderBlueGradientBrush}" Width="26" Height="26" BorderBrush="{DynamicResource MyBorderBlueGradientBrush}">
<Label x:Name="Pin" FontSize="18" Foreground="White" Content="" Width="25" Height="25" Background="Black" HorizontalAlignment="Center" VerticalAlignment="Center">
<Label.RenderTransform>
<RotateTransform Angle="16" CenterX="29" CenterY="0"></RotateTransform>
</Label.RenderTransform>
</Label>
</Label>
</ToggleButton>
</Grid>
When I run this code, I got this window.
So My question is "How the content change into pin image".When I change the content it convert in other image.
The pin is coming from a character from the Webdings FontFamily in your XAML:
<Label x:Name="Pin" FontSize="18" Foreground="White" Content="" Width="25"
Height="25" Background="Black" HorizontalAlignment="Center"
VerticalAlignment="Center" />
Note the Content property... obviously, you can't see the character here, because that font is not common on websites. Also note the FontFamily declared in the ToggleButton:
<ToggleButton x:Name="pinButton" VerticalAlignment="Center" Width="auto" MaxWidth="26"
Height="26" Background="Blue" Focusable="False" DockPanel.Dock="Right"
BorderThickness="0" OverridesDefaultStyle="False" BorderBrush="Blue"
FontFamily="Webdings">

How to reference a static resource from within a datatemplate

I have the following problem:
<DataTemplate x:Key="OrganisationsItemTemplate">
<StackPanel VerticalAlignment="Top" Margin="5,0,0,0">
<Button Command="{Binding Path=DataContext.LoadSpacesCommand, ElementName=OrganisationList}" CommandParameter="{Binding}" Padding="-5,0,-5,-5" Margin="-7,-12,-7,-7" Height="auto" BorderThickness="0" HorizontalAlignment="Left" VerticalAlignment="Stretch" HorizontalContentAlignment="Left" UseLayoutRounding="True" FontSize="0.01">
<Grid Margin="0,0,5,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="67"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Background="Transparent">
<Border Background="White" BorderThickness="0" Width="62" Height="62" HorizontalAlignment="Left" Margin="0,0,0,5">
<Image Source="{Binding image.thumbnail_link}" Width="62" Height="62"></Image>
</Border>
</StackPanel>
<StackPanel Grid.Column="1" VerticalAlignment="Center" Background="Transparent">
<!--<TextBlock Text="{Binding name}" HorizontalAlignment="Left" FontSize="30" VerticalAlignment="Center" Margin="0,0,0,5" />-->
<phone:LongListSelector x:Name="SpacesList"
Background="Transparent"
ItemTemplate="{StaticResource SpacesTemplate }"
ItemsSource="{Binding spaces}"
Margin="40,0,0,96"
LayoutMode="List"
HideEmptyGroups="True"
IsGroupingEnabled="False" VerticalContentAlignment="Top">
</phone:LongListSelector>
</StackPanel>
</Grid>
</Button>
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="SpacesTemplate">
<Border Background="Transparent" Padding="5,0,0,5">
<Border Background="{StaticResource PhoneAccentBrush}" BorderBrush="{StaticResource PhoneAccentBrush}" BorderThickness="2" Width="62"
Height="62" Margin="0,0,18,0" HorizontalAlignment="Left">
<TextBlock Text="{Binding name}" Foreground="{StaticResource PhoneForegroundBrush}" FontSize="48" Padding="6"
FontFamily="{StaticResource PhoneFontFamilySemiLight}" HorizontalAlignment="Left" VerticalAlignment="Center"/>
</Border>
</Border>
</DataTemplate>
In my data template I am placing LongListselector... which also needs a template. but the SpacesTemplate that is defined outside the current datatemplate cannot be seen. any ideas how to reference the datatemplate "SpacesTemplate" from within the datatemplate "OrganisationsItemTemplate"
Xaml is read top down, if you want to use SpacesTemplate inside OrganisationsItemTemplate you will have to put SpacesTemplate before OrganisationsItemTemplate in the Xaml

Categories

Resources