|
Well, actually, I put in the callback for testing and ended up breaking my code
If it's not broken, fix it until it is
|
|
|
|
|
I assume the rogue ;value is just a typo in your message?
var dayNameCaption = control.DayNameCaption;value
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
You don't need to implement INotifyPropertyChanged when you're using dependency properties.
DependencyProperties or INotifyPropertyChanged ?[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Yes, you're correct. For some reason I was thinking the underlying source still need to be explicitly hooked, but it does not.
|
|
|
|
|
It should be,
<TextBlock Text="{Binding DayNameCaption, RelativeSource={RelativeSource FindAncestor, AncestorType={UserControl}}}"... /> You don't need the callback.
"As beings of finite lifespan, our contributions to the sum of human knowledge is one of the greatest endeavors we can undertake and one of the defining characteristics of humanity itself"
|
|
|
|
|
I have been trying for several days to come up with a solution for the my application page. My page contains an upper section with a menu, page header, and two columns for a human head silhouette image and empty white section. That section works fine. What I have been trying to add to my page are two DataGrids side by side so it will create a single table of a total of four columns. Now on each DataGrid the first column is a Description and the second column is the Value it displayed for the Description. What I am trying to do is have a table on the page that appears to make up a single table with 17 rows of Description/values. I don't want either DataGrid to have a scroll bar and each not to be able to scroll. In some of the DataGrid cell a want a background color of blue. Now on the page this table is in a DockPanel with a height of 368 units. What I want is the DockPanel to have a scroll bar so both DataGrids can be scrolled up and down as a single table. First, I have found the it is almost impossible to change the background of a DataGrid Column's Cell. Next my DockPanel scroll bar does not appear and each of the DataGrids are still able to scroll. Below is both the XAML and the code behind. I am only showing 8 rows for testing. If anyone can help that would be great.
Page XAML
<ScrollViewer Height="368" Width="900" VerticalScrollBarVisibility="Auto">
<DockPanel Background="White" Height="368" VerticalAlignment="Top">
<DataGrid Name="main1" ScrollViewer.CanContentScroll="False" AutoGenerateColumns="False" BorderBrush="White" DockPanel.Dock="Left" HorizontalAlignment="Left" Width="495" >
<DataGrid.Columns>
<DataGridTextColumn FontSize="14" FontWeight="Bold" Header="Test Description" Binding="{Binding Description }" />
<DataGridTextColumn FontSize="14" FontWeight="Bold" Binding="{Binding Value}" />
</DataGrid.Columns>
</DataGrid>
<DataGrid Name="main1" ScrollViewer.CanContentScroll="False" AutoGenerateColumns="False" BorderBrush="White" DockPanel.Dock="Left" HorizontalAlignment="Left" Width="495" >
<DataGrid.Columns>
<DataGridTextColumn FontSize="14" FontWeight="Bold" Header="Test Description" Binding="{Binding Description }" />
<DataGridTextColumn FontSize="14" FontWeight="Bold" Binding="{Binding Value}" />
</DataGrid.Columns>
</DataGrid>
</DockPanel>
</ScrollViewer>
Code behind:
List<InformationValues> InformationValuess = new List<InformationValues>();
List<InformationValues> InformationValuess2 = new List<InformationValues>();
List<InformationValues> InformationValuess3 = new List<InformationValues>();
List<InformationValues> InformationValuess4 = new List<InformationValues>();
InformationValuess.Add(new InformationValues() { Description = "Test Description1", Value = "Test Value1" });
InformationValuess.Add(new InformationValues() { Description = "Test Description2", Value = "Test Value2" });
InformationValuess.Add(new InformationValues() { Description = "Test Description3", Value = "Test Value3" });
InformationValuess.Add(new InformationValues() { Description = "Test Description4", Value = "Test Value4" });
InformationValuess2.Add(new InformationValues() { Description = "Test Description1", Value = "Test Value1" });
InformationValuess2.Add(new InformationValues() { Description = "Test Description2", Value = "Test Value2" });
InformationValuess2.Add(new InformationValues() { Description = "Test Description3", Value = "Test Value3" });
InformationValuess2.Add(new InformationValues() { Description = "Test Description4", Value = "Test Value4" });
InformationValuess3.Add(new InformationValues() { Description = "Test Description1", Value = "Test Value1" });
InformationValuess3.Add(new InformationValues() { Description = "Test Description2", Value = "Test Value2" });
InformationValuess3.Add(new InformationValues() { Description = "Test Description3", Value = "Test Value3" });
InformationValuess3.Add(new InformationValues() { Description = "Test Description4", Value = "Test Value4" });
InformationValuess4.Add(new InformationValues() { Description = "Test Description1", Value = "Test Value1" });
InformationValuess4.Add(new InformationValues() { Description = "Test Description2", Value = "Test Value2" });
InformationValuess4.Add(new InformationValues() { Description = "Test Description3", Value = "Test Value3" });
InformationValuess4.Add(new InformationValues() { Description = "Test Description4", Value = "Test Value4" });
main1.ItemsSource = InformationValuess;
main2.ItemsSource = InformationValuess2;
|
|
|
|
|
Change your datasource to a single collection and use a datagrid.
Create a model to meet your view requirements either in the VM or code behind. It should probably have 4 properties for display and 2 object properties to have the underlying data object if you need to do any additional processing when the user interacts with the selected value.
Bind the single collection to a datagrid and forget your scrollviewer.
See if the datagrid supports a CellStyleSelector (I use Telerik tools and they have this concept). I'm pretty sure there are some implementations for the standard tooling out there.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Using a single object with all four properties is definitely the way to go and solves all of my problems except changing the background color of some of the DataGrid cells to blue. I read several articles yesterday and tried to implement the code for turning different DataGrid cells to blue but was unable to get any of the procedures working. This DataGrid is not like the Telerik and has no cell style to do the job. If anyone has something that they have implemented working please let me know.
|
|
|
|
|
Add fields to the model for each cell you need couloured. Bind the cells background to the cell, it may need a converter if the background cannot process the string colour name.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
With WPF and MVVM, properties of the ViewModel are bound to UI elements. When a property changes, its set accessor calls OnPropertyChanged which in turn raises the PropertyChanged event of the INotifyProptyChanged interface.
But it is possible to call OnPropertyChanged (with the property name as argument) from anywhere in the ViewModel (and then you can't use the CallerMemberName attribute).
Now I'd like to ask you: how do you handle such cases? Do you call OnPropertyChanged from other places than the property_set ? Or do you change your code such that you call the property_set ? Or other ideas?
|
|
|
|
|
You can call it from anywhere; it's purpose is to notify the "UI" that there is new info in the data source and the "display" needs updating.
The point is, you may have an updated data source but that does NOT imply that the UI has to also be updated at that point ... maybe the update should be deferred (for now).
For example, I have a real-time app that displays many "numbers" that are calculated; some fields on the display are based on other numbers being displayed. There is no point doing "UI updates" for each calculation ... I do all my calcs, then I call OnPropertyChanged at the end of my calc routine.
|
|
|
|
|
Hi all,
This is my very first WPf-project, so please have some consideration and don’t advise me on MVVM .
Everything I in my project is working fine except one thing:
Whenever I hit the enter key on my keyboard a button gets the click event.
This button is not default button and the only event registered with this button is the click-event.
This is driving me insane.
If I put a breakpoint in the click event handler the routedEventsArgs e is button base click.
Here is the code related to this problem:
<Style x:Key="ButtonStyle" TargetType="Button">
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="Foreground" Value="White" />
<Setter Property="IsEnabled" Value="True" />
<Setter Property="Width" Value="Auto" />
<Setter Property="Height" Value="Auto" />
<Setter Property="Margin" Value="14,5,0,5" />
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Offset="0" Color="Black" />
<GradientStop Offset="1" Color="#FFC41B1B" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid Background="{TemplateBinding Background}">
<ContentPresenter x:Name="MyContentPresenter"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Content="{TemplateBinding Content}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="#7d7f74" />
<Setter Property="Background" Value="#31302c" />
</Trigger>
<Trigger Property="IsKeyboardFocused" Value="true">
<Setter Property="Foreground" Value="Goldenrod" />
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Foreground" Value="Goldenrod" />
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="ButtonTextBlock" TargetType="TextBlock">
<Setter Property="Foreground" Value="White" />
<Setter Property="FontFamily" Value="Trebuchet" />
<Setter Property="FontSize" Value="14" />
<Setter Property="Foreground" Value="White" />
<Setter Property="Background" Value="#000000FF" />
<Setter Property="TextAlignment" Value="Center" />
<Setter Property="Width" Value="95" />
<Setter Property="Padding" Value="5" />
<Setter Property="Margin" Value="0,8,0,8" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Foreground" Value="Goldenrod" />
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="#7d7f74" />
<Setter Property="Background" Value="#31302c" />
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="TextBoxTextBlock" TargetType="TextBlock">
<Setter Property="Foreground" Value="White" />
<Setter Property="FontFamily" Value="Trebuchet" />
<Setter Property="FontSize" Value="14" />
<Setter Property="Foreground" Value="White" />
<Setter Property="Background" Value="#000000FF" />
<Setter Property="TextAlignment" Value="Center" />
<Setter Property="Width" Value="80" />
<Setter Property="Padding" Value="5" />
<Setter Property="Margin" Value="0,8,0,8" />
<Setter Property="Height" Value="Auto" />
<Style.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="#7d7f74" />
<Setter Property="Background" Value="#31302c" />
</Trigger>
</Style.Triggers>
</Style>
And:
<Button x:Name="buttonReset"
Click="buttonReset_Click"
Style="{StaticResource ButtonStyle}">
<TextBlock Style="{StaticResource ButtonTextBlock}">
<Run Text="Reset" />
<LineBreak /><Run Text="alles" />
</TextBlock>
</Button>
code behind:
private void buttonReset_Click(object sender, RoutedEventArgs e)
{
if (!buttonReset.IsKeyboardFocused) return;
ResetAll();
buttonNwOpdrNr.IsEnabled = true;
buttonZoeken.IsEnabled = true;
}
What can cause this behavior ?
Thanks in advance,
Groover
0200 A9 23
0202 8D 01 80
0205 00
|
|
|
|
|
If your button has the focus then enter will invoke the click event.
If all other controls are read only then your button may automatically get the focus.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thank You for Your reply, now it is obvious that the button automatically gets focus, but I could not see difference in appearance of the button. I'll fix that.
How can I prevent any control to get keyboard focus other than with the TAB-key or mouse-click?
It is a disaster when my application gets a reset when the ENTER-key is accidentally hit.
0200 A9 23
0202 8D 01 80
0205 00
|
|
|
|
|
Take a look into the FocusManager, this is my primary grid declaration.
<Grid Style="{StaticResource InfoGrid}"
FocusManager.FocusedElement="{Binding ElementName=txtAuthoriser}">
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I created a grid based XAML page. In the grid I display images which require no negative top margin, vertical, values. In my page I have two labels in textblocks that will not align properly in their grid stack panel with out using negative top margin values in the textblocks. The first label textblock I have to use a Margin="0,-35,0,0" and the second I have to use Margin="0, -650, 0, 0. The XAML is below. One final thing. After what you see I need a table to display labels in several rows and columns. Each row might have different width columns. In my design what is recommended for that?
<Window
x:Class="MasterPage.ApplicationInfoWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:v="clr-namespace:MasterPage"
Title="Intake 4" Height="900" Width="1000" Background="#FFD9DDE8">
<DockPanel>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
</Grid>
<StackPanel >
<Border Margin="0, 0, 0, 0" BorderBrush="Black" BorderThickness="1">
<StackPanel Height="133" VerticalAlignment="Top" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2">
<StackPanel>
<Image Source="Images\header.jpg" Stretch="Fill" DockPanel.Dock="Top" Height="47" />
</StackPanel>
<StackPanel Margin="3,0,0,5" HorizontalAlignment="Left">
<Image Source="Images\DSPASS_logo.png" Width="324" Stretch="Fill" DockPanel.Dock="Top" Height="80" />
</StackPanel>
<StackPanel DockPanel.Dock="Top" HorizontalAlignment="Right" >
<TextBlock FontSize="15" TextWrapping="WrapWithOverflow" Height="25" Margin="0,-35,0,0" >
<Label FontSize="10" HorizontalContentAlignment="Right" HorizontalAlignment="Right" Name="Namelabel" Width="230" FontWeight="Bold" Foreground="#1664A1" Content="Name"/>
</TextBlock>
</StackPanel>
</StackPanel>
</Border>
<Border Margin="0, 0, 0, 0" BorderBrush="Black" BorderThickness="1">
<StackPanel Background="wHITE" Height="358" VerticalAlignment="Top" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="1">
<StackPanel>
<Image Source="Images\silhouette.jpg" VerticalAlignment="Top" HorizontalAlignment="Left" Width="320" Stretch="Fill" DockPanel.Dock="Top" Height="360" />
</StackPanel>
<StackPanel VerticalAlignment="Top" >
<TextBlock FontSize="15" HorizontalAlignment="Right" Height="75" Margin="0, -650, 0, 0" TextWrapping="WrapWithOverflow" >
<Label FontSize="35" HorizontalContentAlignment="Left" Name="Namelabel2" Width="640" FontWeight="Bold" Foreground="#1664A1" Content="Name"/>
</TextBlock>
</StackPanel>
</StackPanel>
</Border>
</StackPanel>
</DockPanel>
</Window>
modified 23-Jul-16 8:09am.
|
|
|
|
|
I did find an answer to my question by just modifying a couple of properties and adding a new stack panel. As you can see new stackpanels were added using the attribute Orientation="Horizontal. So the grid now works without adding negtive margin values. Now the only thing I'm working on is trying to add a table sub grid as mentioned above. If anyone has any ideas there that would help. Thanks.
<Window
x:Class="MasterPage.ApplicationInfoWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:v="clr-namespace:MasterPage"
Title="Intake 4" Height="900" Width="1000" Background="#FFD9DDE8">
<DockPanel>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
</Grid>
<StackPanel >
<Border Margin="0, 0, 0, 0" BorderBrush="Black" BorderThickness="1">
<StackPanel Height="133" VerticalAlignment="Top" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2">
<StackPanel>
<Image Source="Images\header.jpg" Stretch="Fill" DockPanel.Dock="Top" Height="47" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<StackPanel Margin="3,0,0,5" HorizontalAlignment="Left">
<Image Source="Images\DSPASS_logo.png" Width="324" Stretch="Fill" DockPanel.Dock="Top" Height="80" />
</StackPanel>
<StackPanel HorizontalAlignment="Right" Margin="400, 0, 0, 0" >
<TextBlock FontSize="15" TextWrapping="WrapWithOverflow" Height="25" Margin="0,60,0,0" >
<Label FontSize="10" HorizontalContentAlignment="Right" HorizontalAlignment="Right" Name="Namelabel" Width="230" FontWeight="Bold" Foreground="#1664A1" Content="Name"/>
</TextBlock>
</StackPanel>
</StackPanel>
</StackPanel>
</Border>
<Border Margin="0, 0, 0, 0" BorderBrush="Black" BorderThickness="1">
<StackPanel Background="wHITE" Orientation="Horizontal" Height="358" VerticalAlignment="Top" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="1">
<StackPanel>
<Image Source="Images\silhouette.jpg" VerticalAlignment="Top" HorizontalAlignment="Left" Width="320" Stretch="Fill" DockPanel.Dock="Top" Height="360" />
</StackPanel>
<StackPanel>
<TextBlock FontSize="15" HorizontalAlignment="Right" Height="75">
<Label FontSize="35" HorizontalContentAlignment="Left" Name="Namelabel2" Width="640" FontWeight="Bold" Foreground="#1664A1" Content="Name"/>
</TextBlock>
</StackPanel>
</StackPanel>
</Border>
</StackPanel>
</DockPanel>
</Window>
|
|
|
|
|
After doing a lot of research I found the answer to my problem. See the code below. I now understand a lot more about XAML then I did before. From the code below I now know how to do the upper portion of my page but am lost about how to finish my page.Now my confusion is the bottom part of my page needs to be as set of several vertically tables, two per row, with headers and three columns per table. I think that I need to use grids to do this but still am not sure. If someone could point me in the right direction that would be great.
<Window
x:Class="MasterPage.ApplicationInfoWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:v="clr-namespace:MasterPage"
Title="Intake 4" Height="900" Width="1000" Background="#FFD9DDE8">
<StackPanel>
<Border Margin="0, 0, 0, 0" BorderBrush="Black" BorderThickness="1">
<StackPanel Height="133" VerticalAlignment="Top">
<Image Source="Images\header.jpg" Stretch="Fill" Height="47" />
<DockPanel Margin="3,0,0,5">
<Image DockPanel.Dock="Left" Source="Images\DSPASS_logo.png" Width="324" Stretch="Fill" Height="80" />
<Label DockPanel.Dock="Right" FontSize="10" HorizontalContentAlignment="Right" HorizontalAlignment="Right" VerticalAlignment="Bottom" Name="Namelabel" Width="230" FontWeight="Bold" Foreground="#1664A1" Content="Name"/>
</DockPanel>
</StackPanel>
</Border>
<Border Margin="0, 0, 0, 0" BorderBrush="Black" BorderThickness="1">
<DockPanel Background="White" Height="358" VerticalAlignment="Top">
<Image DockPanel.Dock="Left" Source="Images\silhouette.jpg" VerticalAlignment="Top" HorizontalAlignment="Left" Width="320" Stretch="Fill" Height="360" />
<Label DockPanel.Dock="Right" FontSize="35" HorizontalContentAlignment="Left" Name="Namelabel2" Width="640" FontWeight="Bold" Foreground="#1664A1" Content="Name"/>
</DockPanel>
</Border>
</StackPanel>
</Window>
|
|
|
|
|
I'm creating a List type of control[^].
The ListBox's DataTemplate will be an Expander.
Each Expander will have UserControls added to it from the code behind at runtime. How do I ensure that the control is added to the correct Expander?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
Track each Expander's control reference.
|
|
|
|
|
I have a XAML window that the layout is done using a main grid. The problem is when the browser is resized the controls in the second and third columns move to the right and the window's layout is no longer correct. I have pasted the XAML below. I think the layout of a WPF window should be grid based with all controls residing in the window's master grid. Is this the proper layout design for WPF or is there a different recommended layout pattern? Also, I find myself having to use negative value in margins. This confuses me greatly as well.
<Window x:Class="MasterPage.Intake1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:v="clr-namespace:MasterPage.View"
Title="Intake 1" Height="900" Width="1000" Background="#FFD9DDE8" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="35*"/>
<RowDefinition Height="45*"/>
<RowDefinition Height="190*"/>
<RowDefinition Height="275*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="500*"/>
<ColumnDefinition Width="300*"/>
<ColumnDefinition Width="250*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="0">
<Image Source="Images\header.jpg" Height="47" Margin="0,0,0,0" />
</StackPanel>
<StackPanel HorizontalAlignment="Left" Grid.Column="0" Height="80" Width="350" Grid.ColumnSpan="1" Grid.Row="1" Margin="0,-23,0,0">
<Image Source="Images\DSPASS_logo.png" Stretch="Fill" DockPanel.Dock="Top" Height="70" />
</StackPanel>
<StackPanel Grid.Column="4" Grid.Row="1" Grid.ColumnSpan="1" Margin="0,0,0,0">
<TextBlock FontSize="15" Margin="0,0,0,0" Height="25" Width="300" TextWrapping="WrapWithOverflow">
<Label FontSize="10" Name="Namelabel" Width="250" FontWeight="Bold" Foreground="#1664A1" Content="Welcome to DS PASS:"/>
</TextBlock>
</StackPanel>
<StackPanel Grid.Column="0" Grid.Row="2" HorizontalAlignment="Left" Margin="10,10,0,0" Height="290" Width="975" VerticalAlignment="Top" Grid.ColumnSpan="3" Grid.RowSpan="1">
<Label Height="36" FontSize="16" Content="Post Identification" Background="#FF014E7E" FontWeight="Bold" Foreground="White" Margin="-5,0,-18,0"/>
<StackPanel x:Name="_wordLength" Orientation="Horizontal" Margin="235,0,200,0">
<TextBlock Height="20" x:Name="ApplicantType_TextBlock" Text="Applicant Type" Width="110" Margin="5" TextAlignment="Right"/>
<ComboBox Height="25" x:Name="textBoxWordLength" Width="400" Margin="10,5"/>
</StackPanel>
<StackPanel x:Name="_integerWordLength" Orientation="Horizontal" Margin="235,0,200,0">
<TextBlock Height="20" x:Name="textBlockIntegerWordLength" Text="Person Type" Width="110" Margin="5" TextAlignment="Right"/>
<ComboBox Height="25" x:Name="textBoxIntegerWordLength" Width="400" Margin="10,5"/>
</StackPanel>
<StackPanel x:Name="_Post" Orientation="Horizontal" Margin="235,0,200,20">
<TextBlock Height="20" x:Name="Post_TextBlock" Text="Post" Width="110" Margin="5" TextAlignment="Right"/>
<ComboBox Height="25" x:Name="Post_TextBox" Width="400" Margin="10,5"/>
</StackPanel>
</StackPanel>
<StackPanel Grid.Column="0" Grid.Row="3" HorizontalAlignment="Left" Height="130" Margin="15,-120,0,0" VerticalAlignment="Top" Grid.ColumnSpan="3" >
<Label Height="36" FontSize="16" Content="Applicant Employment" Background="#FF004A78" FontWeight="Bold" Foreground="White" Margin="-5,0,-18,0"/>
<StackPanel x:Name="_max1" Orientation="Vertical" Margin="1,0,355,0">
<TextBlock Height="20" x:Name="maxTextBlock1" Text="Employee ID" Width="100" Foreground="Black" Margin="0,15,459,5" TextAlignment="Right"/>
<TextBox Height="25" x:Name="maxTextBox1" Width="400" Margin="0,-5,90,25"/>
</StackPanel>
</StackPanel>
<StackPanel Grid.Column="0" Grid.Row="4" Grid.ColumnSpan="3" Orientation="Vertical" HorizontalAlignment="Left" Height="330" Margin="0,10,0,0" VerticalAlignment="Top" Width="965" Grid.RowSpan="2">
<Label Height="36" FontSize="16" Content="English Version of Name" Background="#FF005183" Grid.Row="4" FontWeight="Bold" Margin="10,10,0,0" Foreground="White" Padding="4,5,5,5"/>
<StackPanel x:Name="_LastName" Orientation="Vertical">
<TextBlock Height="20" x:Name="LastName_TextBlock" Text="Last Name/Surname" Margin="55,5,459,5" TextAlignment="Left"/>
<TextBox Height="25" x:Name="LastName_TextBox" Width="500" Margin="55,5,459,5"/>
</StackPanel>
<StackPanel x:Name="_FirstName" Orientation="Vertical">
<TextBlock Height="20" x:Name="FirstName_TextBlock" Text="First Name" Margin="55,0,459,0" TextAlignment="Left"/>
<TextBox Height="25" x:Name="FirstName_TextBox" Width="500" Margin="55,0,459,0"/>
</StackPanel>
<StackPanel x:Name="_MiddleName" Orientation="Vertical">
<TextBlock Height="20" x:Name="MiddleName_TextBlock" Text="Middle Name" Margin="55,5,459,5" TextAlignment="Left"/>
<TextBox Height="25" x:Name="MiddleName_TextBox" Width="500" Margin="55,5,459,5"/>
</StackPanel>
<StackPanel x:Name="_ExtendedName" Orientation="Vertical">
<TextBlock Height="20" x:Name="ExtendedName_TextBlock" Text="Extended name (Tribal, Jr., III, etc.)" Margin="55,5,372,5" TextAlignment="Left"/>
<TextBox Height="25" x:Name="Extended_TextBox" Width="500" Margin="55,5,459,5"/>
</StackPanel>
</StackPanel>
<StackPanel Grid.RowSpan="4" Grid.Column="4" HorizontalAlignment="Left" Height="230" Margin="-250,400,0,0" Width="480" Grid.ColumnSpan="1">
<StackPanel x:Name="_Aliases" Orientation="Vertical" Margin="-15,0,0,0" Height="144">
<TextBlock Height="20" x:Name="Aliases_TextBlock" Text="Aliases" Margin="40,-5,0,5" TextAlignment="Left"/>
<TextBox Height="25" x:Name="Aliases_TextBox" Width="500" Margin="43,5"/>
<TextBox Height="25" x:Name="Aliases_TextBox1" Width="500" Margin="43,5"/>
<TextBox Height="25" x:Name="Aliases_TextBox2" Width="500" Margin="43,5"/>
</StackPanel>
</StackPanel>
<Label HorizontalAlignment="Left" Margin="4,400,0,0" Grid.Row="4" VerticalAlignment="Top" Background="#FF52BB52" Grid.ColumnSpan="3" Width="983" Height="36">
</Label>
<Button Content="Save Draft" Grid.Column="1" HorizontalAlignment="Left" Margin="150,408,0,0" Grid.Row="5" VerticalAlignment="Top" Width="125" />
<Button x:Name="ContinueButton_Page2" Content="Continue" Grid.Column="1" Width="125" Grid.Row="5" VerticalAlignment="Top" Margin="200,408,0,0" Grid.ColumnSpan="2" Click="btnContinue_Click"/>
</Grid>
</Window>
modified 17-Jul-16 10:51am.
|
|
|
|
|
WPF works for you when your "view" is laid out in a logical manner; yours is not; it is particularly obvious if you look at your XAML in the "document outline" and "design" windows.
StackPanels are hard to control; it's easier / more intuitive using "Grids within Grids".
You should not be altering "heights" and "margins" (from their defaults) to affect positioning; the "styles" (i.e. height, width, etc.) of the individual controls should drive the (automatic) layout.
Start by removing the height and width of the window and look at the properties that relate to its content; e.g. StartupLocation; SizeToContent; WindowState; etc.
|
|
|
|
|
So, I basically took the reordering from Josh Smith:
Drag and Drop Items in a WPF ListView[^]
All I wanted to do now was to draw a line where the new item was inserted, with an arrow. Like the old WinForms style behavior:
Manual reordering of items inside a ListView[^]
The line under was easy to achieve, all I had to was to alter the Style:
<Style x:Key="ItemContStyle" TargetType="ListViewItem">
<Style.Resources>
<LinearGradientBrush x:Key="MouseOverBrush" StartPoint="0.5, 0" EndPoint="0.5, 1">
<GradientStop Color="#22000000" Offset="0" />
<GradientStop Color="#44000000" Offset="0.4" />
<GradientStop Color="#55000000" Offset="0.6" />
<GradientStop Color="#33000000" Offset="0.9" />
<GradientStop Color="#22000000" Offset="1" />
</LinearGradientBrush>
<SolidColorBrush x:Key="SelectedBackgroundBrush" Color="#DDD" />
<SolidColorBrush x:Key="DisabledForegroundBrush" Color="#888" />
</Style.Resources>
<Setter Property="Padding" Value="0,4" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<!--
<Setter Property="Border.BorderThickness" Value="0,0,0,0.5" />
<Setter Property="Border.BorderBrush" Value="Transparent"/>
<!--
<Style.Triggers>
<Trigger Property="jas:ListViewItemDragState.IsBeingDragged" Value="True">
<Setter Property="FontWeight" Value="DemiBold" />
</Trigger>
<Trigger Property="jas:ListViewItemDragState.IsUnderDragCursor" Value="True">
<Setter Property="Border.BorderThickness" Value="0,0,0,0.5" />
<Setter Property="Border.BorderBrush" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
SO I looked at the ControlTemplate for the ListViewItems:
ListViewItem ControlTemplate Example[^]
But as soon as I started to add the ControlTemplate Design the correct behavior stopped:
<Style x:Key="ItemContStyle" TargetType="ListViewItem">
<Style.Resources>
<LinearGradientBrush x:Key="MouseOverBrush" StartPoint="0.5, 0" EndPoint="0.5, 1">
<GradientStop Color="#22000000" Offset="0" />
<GradientStop Color="#44000000" Offset="0.4" />
<GradientStop Color="#55000000" Offset="0.6" />
<GradientStop Color="#33000000" Offset="0.9" />
<GradientStop Color="#22000000" Offset="1" />
</LinearGradientBrush>
<SolidColorBrush x:Key="SelectedBackgroundBrush" Color="#DDD" />
<SolidColorBrush x:Key="DisabledForegroundBrush" Color="#888" />
</Style.Resources>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<Grid>
<Polygon
x:Name="poly_PART"
VerticalAlignment="Bottom"
HorizontalAlignment="Left"
Stroke="Red"
Fill="Red"
StrokeThickness="2"
Points="0,1 0,-1 1,0"
Margin="0,0,0,0"
Width="10"
Height="10"
Stretch="Fill"
/>
<ContentPresenter
Content="{TemplateBinding Content}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Padding" Value="0,4" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<!--
<Setter Property="Border.BorderThickness" Value="0,0,0,0.5" />
<Setter Property="Border.BorderBrush" Value="Transparent"/>
<!--
<Style.Triggers>
<Trigger Property="jas:ListViewItemDragState.IsBeingDragged" Value="True">
<Setter Property="FontWeight" Value="DemiBold" />
</Trigger>
<Trigger Property="jas:ListViewItemDragState.IsUnderDragCursor" Value="True">
<!--
<Setter Property="Border.BorderThickness" Value="0,0,0,0.5" />
<Setter Property="Border.BorderBrush" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
How do I fix this issue?
|
|
|
|
|
Here is a common way of having a ViewModel's property with the INotifyPropertyChanged interface:
string text;
public string Text
{
get { return text; }
set
{
if (value != text)
{
text = value;
NotifyPropertyChanged(nameof(Text));
}
}
}
This occupies one line for the member variable and twelve lines for the property.
In my ViewModel I have many properties and the code is getting very huge due to each property need the above body to include the NotifyPropertyChanged method and a member varible.
I prefer my properties to be defined in this way:
public string Text { get; set; }
That property's body is just one line and I don't need to define a member variable.
But I cannot find out how to call the NotifyPropertyChanged method.
Is there a solution to short the body of the property and still have the call to the NotifyPropertyChanged method?
For instance:
* Having a property without the need of a member variable.
* Define the property as close as possible to: public string Text { get; set; } .
* Having the call to the NotifyPropertyChanged in the setter body.
Best regards,
/Steffe
|
|
|
|
|
Mc_Topaz wrote: Is there a solution to short the body of the property and still have the call to the NotifyPropertyChanged method? No.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|