Upgrade to Visual Studio 2015 gives false errors - c#

I have upgraded a project from VS 2012 to VS 2015 and I am getting bizarre errors. On some windows it complains about Color and Brush definitions even though I am doing absolutely nothing with any colors or brushes. The project will compile but the editor gives errors. As an example, on the XAML code:
<ComboBox x:Name="cbCountry" Grid.Column="1" VerticalAlignment="Bottom" Height="28" FontSize="12" SelectionChanged="cbCountry_SelectionChanged"
HorizontalContentAlignment="Stretch" IsEditable="True" StaysOpenOnEdit="True" IsManipulationEnabled="True" KeyUp="cbCountry_KeyUp" />
complains about the color. Huh? What color? This is a pretty vanilla page with nothing fancy going on, anybody have any ideas how to eliminate these errors?
Update
I had some windows resources defined as:
<Window.Resources>
<DataTemplate x:Key="CityTemplate">
<StackPanel Orientation="Horizontal">
<Border BorderThickness="1" BorderBrush="Black">
<TextBlock Text="{Binding City}" />
</Border>
</StackPanel>
</DataTemplate>
</Window.Resources>
which does have a BorderBrush defined, but not for the combo. I tried taking a piece out at a time starting with the BorderBrush. It wasn't until I completely removed the <Windows.Resources> section that the error went away. Does anyone see anything wrong in the Windows Resources to cause this?
Update 2
The problem seems to be independent of any code behind. The entire XAML is below:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ig="http://schemas.infragistics.com/xaml"
x:Class="PTHWPF.View.Lookup"
Title="Lookup Place of Birth" Height="400" Width="600" Loaded="Window_Loaded"
Icon="/PTHWPF;component/Resources/Images/LookupMap.png">
<!--TextBlock.TextAlignment="Center" -->
<Window.Resources>
<DataTemplate x:Key="CityTemplate">
<StackPanel Orientation="Horizontal">
<Border BorderThickness="1" BorderBrush="Black">
<TextBlock Text="{Binding City}" />
</Border>
</StackPanel>
</DataTemplate>
</Window.Resources>
<Grid IsManipulationEnabled="True" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="110" />
<ColumnDefinition Width="280*" />
<ColumnDefinition Width="180*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="60" />
<RowDefinition Height="50" />
<RowDefinition Height="50" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Label Content="Country or State" Height="28" HorizontalAlignment="Right" x:Name="lbCountry" VerticalAlignment="Bottom" />
<ComboBox x:Name="cbCountry" Grid.Column="1" VerticalAlignment="Bottom" Height="28" FontSize="12" SelectionChanged="cbCountry_SelectionChanged"
HorizontalContentAlignment="Stretch" IsEditable="True" StaysOpenOnEdit="True" IsManipulationEnabled="True" KeyUp="cbCountry_KeyUp" >
</ComboBox>
<Label Content="City" Grid.Row="1" Height="28" HorizontalAlignment="Right" x:Name="lbCity" VerticalAlignment="Bottom" />
<ig:XamMultiColumnComboEditor SelectionChanged="cbCity_SelectionChanged"
Grid.Column="1" Grid.Row="1"
HorizontalAlignment="Stretch"
x:Name="cbCity" Height="28"
VerticalAlignment="Bottom"
DataContext="{Binding}"
DisplayMemberPath="City"
HorizontalContentAlignment="Left"
IsTabStop="True" MinWidth="250"
FilterMode="FilterOnPrimaryColumnOnly"/>
<DockPanel Grid.Column="1" Grid.Row="2" HorizontalAlignment="Center" >
<Button Background="#9F7F90FC" Height="30" x:Name="btnOk" Width="80" Style="{DynamicResource RoundedButton}" HorizontalAlignment="Left" IsDefault="True" Click="btnOk_Click" VerticalAlignment="Bottom" Margin="0,0,20,0">
<StackPanel Orientation="Horizontal">
<Image Height="20" Source="/PTHWPF;component/Resources/ok.png" Width="20" />
<AccessText Margin="5,3,0,0" x:Name="btnOkText" Text="_Ok"/>
</StackPanel>
</Button>
<Button Background="#9F7F90FC" BorderBrush="#95FFFFFF" Height="30" x:Name="btnCancel" Style="{DynamicResource RoundedButton}" Width="80" IsCancel="True" Click="btnCancel_Click" VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="20,0,0,0">
<StackPanel Background="{x:Null}" Orientation="Horizontal">
<Image Height="20" Source="/PTHWPF;component/Resources/Images/cancel.png" Width="20" />
<AccessText Margin="5,3,0,0" x:Name="btnCancelText" Text="_Cancel"/>
</StackPanel>
</Button>
</DockPanel>
</Grid>
</Window>

Apparently Visual Studio 2015 Enterprise Edition had some issues, this also included "Handler=..." errors such as found here:
https://connect.microsoft.com/VisualStudio/feedback/details/1611888/xaml-editor-error-invalid-value-for-property-handler-and-ischecked-bug-remains-in-the-enterprise-version-of-vs-2015
I encountered it as well on other XAML files, but it didn't cause the designer to fail.
Solution:
Upgrade to Service Pack 1 found here:
https://www.visualstudio.com/en-us/news/vs2015-update1-vs.aspx
It is a web update and it took over an hour to do. I will also require a reboot of windows to finish, so keep that in mind. Hopefully anyone finding this post won't spend days like I did to fix the problem.

Related

c# wpf form within form

I have just started c# and Wpf. I am trying to build a utility that gets computers from active directory, display them in a treeview and then recover information via WMI. I have managed to get most of this done without asking questions. However I now have a problem with presentation.Current Wpf output
after selecting the information required (disks/printers/services etc) i would like to display the information in the panel to the right. My problem is this infomation may be a tabbed form, a listbox, a gridview or a graphic.ex A tab view What would be my best way to get this result. Thanks in advance.
It's the area currently taken up by " " that should show the different formats.
<StackPanel>
<DockPanel Margin="3">
<Border CornerRadius="6"
BorderBrush="Gray"
Background="LightGray"
BorderThickness="2" >
<StackPanel Background="SkyBlue" Height="80">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<Label Content="Domaine:" HorizontalAlignment="Left" Height="30"/>
<TextBox Name="FrmDomain" HorizontalAlignment="Left" Height="30" Width="80"/>
<Label Content="Zone" Height="30"/>
<TextBox Name="FrmTreeZone" HorizontalAlignment="Left" Height="30" Width="80"/>
<Label Content="Ordinateur:" />
<TextBox Name="FrmTreeOrdi" HorizontalAlignment="Left" Height="30" Width="80"/>
<Label Content="Option:" />
<TextBox Name="FrmTreeOption" HorizontalAlignment="Left" Height="30" Width="80" />
<Label Content="Disponible:" />
<TextBlock Name="FrmTreeAlive" HorizontalAlignment="Left" Height="30" Width="40"/>
</StackPanel>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<Label Content="Recherche:"/>
<TextBox x:Name="FrmRecherche" HorizontalAlignment="Left" Height="30" Width="80"/>
<Button x:Name="btnRech" Click="btnRech_MouseClick" >
<materialDesign:PackIcon Kind="Search"/>
</Button>
<Label Content="Mac:" />
<TextBox x:Name="FrmMac" HorizontalAlignment="Left" Height="30" Width="80"/>
</StackPanel>
</StackPanel>
</Border>
</DockPanel>
<DockPanel Margin="3">
<Border CornerRadius="6"
BorderBrush="Gray"
Background="LightGray"
BorderThickness="2" >
<StackPanel Orientation="Vertical" HorizontalAlignment="Left" Background="LightCyan" MinWidth="300" Width="300">
<TreeView Name="FrmTreeView" Height="540" Margin="8"
SelectedItemChanged="TreeView_SelectedItemChanged"
PreviewMouseRightButtonDown="OnPreviewMouseRightButtonDown"
TreeViewItem.Selected="NodeSelected">
<TreeView.Resources>
<ContextMenu x:Key="TestMenu">
</ContextMenu>
<Style TargetType="TreeViewItem" >
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Width="20" Margin="3" Source="{Binding RelativeSource={RelativeSource Mode=FindAncestor,
AncestorType={x:Type TreeViewItem}},
Path=Tag,
Converter={x:Static local:HeaderToImageConverter.Instance }}"/>
<TextBlock VerticalAlignment="Center" Text="{Binding}"/>
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</TreeView.Resources>
</TreeView>
</StackPanel>
</Border>
<StackPanel Name="test" DockPanel.Dock="Right" Visibility="Visible">
<Border CornerRadius="6"
BorderBrush="Gray"
Background="WhiteSmoke"
BorderThickness="2" >
<TextBlock Name="FrmActionAffiche" Height="540" Margin="8"/>
</Border>
<DataGrid Height="1" Name="FrmDataGrid"/>
</StackPanel>
</DockPanel>
<StackPanel Orientation="Horizontal">
<Button Name="btnDisque" Content="Disque" Height="30" Width="100" Click="btnDisque_MouseClick" />
</StackPanel>
<StackPanel Orientation="Vertical" Height="30">
<StatusBar>
<StatusBar.ItemsPanel>
<ItemsPanelTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="4*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
</Grid>
</ItemsPanelTemplate>
</StatusBar.ItemsPanel>
<StatusBarItem>
<TextBlock>Ready</TextBlock>
</StatusBarItem>
<StatusBarItem Grid.Column="1">
<ProgressBar Value="30" Width="80" Height="18"/>
</StatusBarItem>
<StatusBarItem Grid.Column="2">
<TextBlock>Set</TextBlock>
</StatusBarItem>
<StatusBarItem Grid.Column="3">
<TextBlock>Go!</TextBlock>
</StatusBarItem>
</StatusBar>
</StackPanel>
</StackPanel>
To be able to display different types of information in different ways you should make use of a DataTemplate, you can have multiple DataTemplates and select which one to display based on the type without any additional coding (or program your own logic for selecting the template with a DataTemplateSelector).
For example assuming the TreeView on the left contains items of type Computer and Printer you could bind a control to the SelectedItem property of the TreeView (do display the currently selected item) and add DataTemplates for Type=Printer and Type=Computer to that control to describe how you want to display either of them.
If you post your current code (XAML and C#) i'd be happy to give you an exemple for your specific case.

Access Popup-Dialog inside a data template

I have just started learning windows app development. Like what do we call it (A dialog box, Contentdialogbox, Message Dialog)? Thanks in advance.
Okay I tried this since I have my data in a datatemplate inside a contentpresenter(Making a master detail view) now when user clicks on a icon the popup should open and also display the data related to that event selected inside that list.How do I achieve this since the popup dialog control is defined inside a datatemplate so in my cs file it does not recognize the control so I am not able to open the popup dialog.
Xaml Code:
<DataTemplate x:Key="DetailContentTemplate" x:DataType="data:Event">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="200" />
<RowDefinition Height="50" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid x:Name="Section2" Grid.Row="0">
<Grid.Background>
<ImageBrush ImageSource="ms-appx:///Assets/8.JPG" Stretch="Fill" />
</Grid.Background>
<TextBlock MaxWidth="250"
Margin="36,62,34,68"
FontFamily="Baskerville Old Face"
FontSize="30"
Foreground="{ThemeResource ToggleButtonPressedForegroundThemeBrush}"
TextWrapping="WrapWholeWords"
d:LayoutOverrides="Width, LeftPosition, RightPosition, TopPosition, BottomPosition">
<Run Text="Gravitas Premier League" />
</TextBlock>
</Grid>
<Grid x:Name="Content"
Grid.Row="1"
Margin="0,10,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
<RelativePanel>
<SymbolIcon x:Name="symbol"
Margin="0,0,5,0"
HorizontalAlignment="Left"
RelativePanel.AlignLeftWithPanel="True"
Symbol="Globe" />
<TextBlock HorizontalAlignment="Right"
VerticalAlignment="Top"
RelativePanel.RightOf="symbol"
Style="{ThemeResource BaseTextBlockStyle}"
Text="Category" />
</RelativePanel>
</StackPanel>
<StackPanel Grid.Column="1" HorizontalAlignment="Center">
<RelativePanel>
<SymbolIcon x:Name="symboll"
Margin="0,0,5,0"
HorizontalAlignment="Left"
RelativePanel.AlignLeftWithPanel="True"
Symbol="People" />
<TextBlock HorizontalAlignment="Right"
VerticalAlignment="Top"
RelativePanel.RightOf="symboll"
Style="{ThemeResource BaseTextBlockStyle}"
Text="SubCategory" />
</RelativePanel>
</StackPanel>
<StackPanel Grid.Column="2" HorizontalAlignment="Right">
<RelativePanel>
<SymbolIcon x:Name="symbllol"
Margin="0,0,5,0"
HorizontalAlignment="Left"
RelativePanel.AlignLeftWithPanel="True"
Symbol="Bullets" />
<TextBlock HorizontalAlignment="Right"
VerticalAlignment="Top"
RelativePanel.RightOf="symbllol"
Style="{ThemeResource BaseTextBlockStyle}"
Text="Rupee" />
</RelativePanel>
</StackPanel>
</Grid>
<TextBlock Grid.Row="2"
HorizontalAlignment="Center"
Style="{ThemeResource ScenarioDescriptionTextStyle}"
Text="{x:Bind description}"
TextWrapping="WrapWholeWords" />
<Grid Grid.Row="3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<SymbolIcon Grid.Column="0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Symbol="Phone" />
<SymbolIcon Grid.Column="1"
x:Name="People"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Symbol="People"
IsTapEnabled="True"
Tapped="ShowPopupOffsetClicked"
/>
<SymbolIcon Grid.Column="2"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Symbol="Mail" />
</Grid>
</Grid>
</DataTemplate>
Now how do I open up the popup when the user taps the symbol with the name People and with necessary bindings of data with a observablecollection say EventList.
There are a lot of ways to implement the UI like in your screenshot. As you've added template10 in your question, I suppose you are using Template10 in your project. And in Template10, we can use ModalDialog to implement this. Here I use a Minimal Template 10 project for example.
Firstly, we may need to change ModalBackground to make the background color looks like what in your screenshot. As the ModalDialog we used here is the root frame created by Bootstrapper automatically, so we need override CreateRootElement in App.xaml.cs like:
public override UIElement CreateRootElement(IActivatedEventArgs e)
{
var b = Current;
var frame = new Windows.UI.Xaml.Controls.Frame();
var nav = b.NavigationServiceFactory(BackButton.Attach, ExistingContent.Include, frame);
//change background
var background = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Colors.Gray);
background.Opacity = 0.2;
return new Template10.Controls.ModalDialog
{
ModalBackground = background,
DisableBackButtonWhenModal = true,
Content = nav.Frame
};
}
Then we can edit Busy.xaml to implement the panel in your screenshot. In Busy.xaml, it's a UserControl used as the ModalContent of ModalDialog. For example,
<UserControl x:Class="T10Minimal.Views.Busy"
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:local="using:T10Minimal.Views"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DesignHeight="300"
d:DesignWidth="400"
mc:Ignorable="d">
<Grid Width="300"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Background="White"
CornerRadius="10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
...
</Grid.RowDefinitions>
<TextBlock Margin="20,0"
VerticalAlignment="Center"
FontSize="24"
Foreground="Black">
Song Options
</TextBlock>
<Button Margin="12"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Click="CloseClicked"
Foreground="Black"
Style="{StaticResource TextBlockButtonStyle}">
<SymbolIcon Symbol="Clear" />
</Button>
...
</Grid>
</UserControl>
The bindings might like the BusyText in the original control, you can change its type to your binding data's type and also change the SetBusy method. After this, you can call SetBusy method in your ShowPopupOffsetClicked method to open the "popup".
This is just a simple sample, you can refer to it to implement your own. And in the sample, I used the ModalDialog created as the root frame of the application. If you need more than one ModalDialog, you can refer to Search (and Login) Sample on GitHub.

cannot access programmatically a popup in side listbox

I have a list box and I want a popup control to popup when each row onclicked event I put pop in .xmal but I can't change the isopened="true" programmatically in .cs file here is my .xmal looks like
<ListView Name="listView1" Height="306" HorizontalAlignment="Left" Margin="982,99,0,0" VerticalAlignment="Top" Width="370" SelectionChanged="listView1_SelectionChanged" >
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="Height" Value="58" />
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<DataTemplate>
<Grid Name="g2">
<Grid.RowDefinitions>
<RowDefinition Height="27"/>
<RowDefinition Height="20"/>
</Grid.RowDefinitions>
<Label Name="lblitemname" Grid.Row="0" Content="Item Name" FontSize="20" FontWeight="Medium" Margin="40,0,0,0" FontFamily="Baskerville Old Face" FontStyle="Italic"/>
<Label Name="lblx" Grid.Row="1" FontSize="11" Content="x" FontWeight="Normal" Margin="50,0,0,-5"/>
<Label Name="lblprice" Grid.Row="1" FontSize="11" Content="50.00" FontWeight="Bold" Margin="60,0,0,-5"/>
<Label Name="lblqty" Grid.Row="1" FontSize="11" Content="5" FontWeight="Bold" Margin="40,0,0,-5"/>
<Label Name="lbltotip" Grid.Row="1" FontSize="11" Content="Rs. 250.00" FontWeight="Bold" Margin="250,0,0,-5"/>
<!--This is popup start-->
<StackPanel Margin="50,0,0,0">
<Popup Name="editpop" PopupAnimation="Slide" AllowsTransparency="True" HorizontalOffset="0" VerticalOffset="0" Placement="Right">
<Canvas Width="600" Height="250">
<TextBlock Canvas.Left="75"
Canvas.Top="28"
Width="500"
Height="200"
Text="Please Enter Your Passcode To Log In"
TextWrapping="Wrapwithoverflow"
FontSize="20"
FontWeight="Bold"
Foreground="White"
/>
<PasswordBox Canvas.Left="60" Canvas.Top="70" Name="txtpwd" Grid.Row="3" Height="60" Width="380" FontWeight="Bold" />
</Canvas>
</Popup>
</StackPanel>
<!--This is popup end-->
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
It's a little bit difficult to fully understand your problem from the one sentence that you used to explain it. However, I think that you just need a way to access the Popup control from your DataTemplate. To find out how you can do this, please read the How to: Find DataTemplate-Generated Elements page on MSDN.
Please let me know if I have misunderstood your problem and if I have, then can you please explain it better.

How can I wrap text in a TextBlock?

I am new to windows phone7 development and have a little issue.
I have a textblock(Label) in my interface, and in runtime I use that label to display dyanamic data. The problem is when the text is too long(than the width of the screen), it only displays half of the data(Only the content that fits the width). It doesn't matter to go for multiple lines, but I want to display the full content. I tested with Textblock(Label) properties, but didn't find any working.
Can someone please help me. (I am Using visual studio 2010) . Thanks
Following is the XAML
<Grid x:Name="LayoutRoot" Height="98">
<Ellipse Height="25" HorizontalAlignment="Left" Name="ellipse1" Stroke="Black" StrokeThickness="1" VerticalAlignment="Top" Width="46" Margin="6,13,0,0" Fill="#FFDB4C4C" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="66,10,0,0" Name="textBlock1" Text="TextBlock" VerticalAlignment="Top" Width="402" AllowDrop="False" TextWrapping="NoWrap" UseLayoutRounding="True" DataContext="{Binding}" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="66,44,0,0" Name="textBlock2" Text="TextBlock" VerticalAlignment="Top" Width="402" />
</Grid>
Setting the property TextWrapping = "Wrap" might solve your problem as long as there is enough vertical space.
EDIT
Depending on how you would like the resize behavior this should work:
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="auto" MinHeight="40" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="60" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Ellipse Margin="5" Stroke="Black" StrokeThickness="1" Fill="#FFDB4C4C" />
<TextBlock HorizontalAlignment="Left" Margin="5" Name="textBlock1" VerticalAlignment="Top" TextWrapping="Wrap" UseLayoutRounding="True" Grid.Column="1" Text="sdfsdf sdf sdf sdf sd f sdf" />
<TextBlock HorizontalAlignment="Left" Margin="5" Name="textBlock2" VerticalAlignment="Top" TextWrapping="Wrap" Grid.Column="1" Grid.Row="1" Text="sdfsdf sdf sdf sdf sd f sdf" />
</Grid>

Splitting Button in Half

I'm trying to split a button in half so that I can show text data in each half - which can also be increased in size when the application is expanded.
This is the code I've got soo far.
<Button Margin="16,0,16,6" Background="#daf0fc" BorderThickness="0" Height="Auto" HorizontalAlignment="Stretch" BorderBrush="White" Click="edit_house" Padding="0" Focusable="False">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Orientation="Vertical" VerticalAlignment="Top" HorizontalAlignment="Left" Background="Black">
<StackPanel Orientation="Horizontal">
<TextBlock Margin="0,0,5,0" Text="{Binding house_number}" FontWeight="Bold" FontSize="14" />
<TextBlock Margin="0,0,0,0" Text="{Binding street}" FontWeight="Bold" FontSize="14" />
</StackPanel>
<TextBlock Text="{Binding postcode}" />
<TextBlock Margin="0,6,0,0" Text="{Binding house_type_text}" />
</StackPanel>
<StackPanel Grid.Column="1" Orientation="Vertical" VerticalAlignment="Top">
<StackPanel Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="0,2,0,0">
<TextBlock Text="£" HorizontalAlignment="Right" Foreground="#FF9D1818" FontWeight="ExtraBold" FontSize="16" />
<TextBlock Text="{Binding house_price}" HorizontalAlignment="Right" Foreground="#FF9D1818" FontWeight="ExtraBold" FontSize="16" />
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Margin="0,0,0,0">
<TextBlock Margin="0,0,0,0" Text="{Binding sold_text}" HorizontalAlignment="Right" Foreground="#FF107910" FontWeight="ExtraBold" FontSize="14" />
</StackPanel>
</StackPanel>
I've tried setting each StackPanel half to stretch, but they both just Float in the centre of the button, so I can't align the text on either half.
Here's a graphical representation of the button I'm trying to create...
Update:
Here is what I'm getting with the code above, sadly I'm struggling to get the text to align, or to get anything to stretch to the full width of each half:
StackPanel won't do that; it just stacks elements.
Instead, use a <Grid> with two columns.
StackPanel is not the right container for this. Try using a Grid like this:
<Button>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
...
</StackPanel>
<StackPanel Grid.Colunn="1">
...
</StackPanel>
</Grid>
</Button>
I like to use UniformGrids, although a Grid will also work if you need to define your Rows/Columns individually
Here's an example, with correct alignments:
<UniformGrid Columns="2">
<StackPanel Background="LightBlue" >
<StackPanel Orientation="Horizontal">
<TextBlock Margin="0,0,5,0" Text="123" FontWeight="Bold" FontSize="14" />
<TextBlock Margin="0,0,0,0" Text="Main Street" FontWeight="Bold" FontSize="14" />
</StackPanel>
<TextBlock Text="12345" />
<TextBlock Margin="0,6,0,0" Text="Type" />
</StackPanel>
<StackPanel Background="Yellow">
<StackPanel Orientation="Horizontal" VerticalAlignment="Top" Margin="0,2,0,0" HorizontalAlignment="Right">
<TextBlock Text="£" HorizontalAlignment="Right" Foreground="#FF9D1818" FontWeight="ExtraBold" FontSize="16" />
<TextBlock Text="100.00" HorizontalAlignment="Right" Foreground="#FF9D1818" FontWeight="ExtraBold" FontSize="16" />
</StackPanel>
<TextBlock Margin="0,0,0,0" Text="200.00" HorizontalAlignment="Right" Foreground="#FF107910" FontWeight="ExtraBold" FontSize="14" />
</StackPanel>
</UniformGrid>
You might also be interested in checking out this link, which gives you a quick visual look at each of WPF's different layouts and how they act.

Categories

Resources