|
And that's why I use user controls and "code-behind". Ship now or ship maybe.
Why a "binding" instead of just a menu command parameter "constant" or "enum"? How many ways can you "add a company"?
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Gerry Schmitz wrote: And that's why I use user controls and "code-behind". Ship now or ship maybe.
Not sure what that means
Gerry Schmitz wrote: Why a "binding" instead of just a menu command parameter "constant" or "enum"? How many ways can you "add a company"?
Binding? As opposed to....?
Not sure what this response means. How else would this be done? I'm using a command that bound to the menu bars.
If I understand what you're asking, I decided to use one command for all menu bars. This way I don't have to have a command and Execute/CanExecute for each bar.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
For example:
<MenuItem x:Name="newCompanyButton"
Command="{Binding NewItemCommand}"
CommandParameter="{Binding RelativeSource={RelativeSource Self}}"
CommandParameter="{x:Static local:ActionId.NewCompany}"
Tag="company"
Header="New Company" />
And "Tag" is your parameter. How many do you need?
Or, menu click "sender" identifies the menu item.
Your could even examine the "header"; or the "Name".
A lot of "binding" for nothing, and only confusing for the next person.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Why not pass the "tag" value as a commandparameter?
Seems to me you should be using the enabled property when constructing the menu to manage access via the app security not the canexecute which logically only fires when the item is clicked!
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
Can execute fires alot, like when the window refreshes. I want the b as r disabled BEFORE the user can click on it
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Your canexecute defines if the user can execute the menu item based on the users security profile (or am I missing something), why are you not disabling the menu item when you construct the menu, or don't even add the item if the user does not have permissions.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
Constructing the menu happens once. The security profile can change at runtime, for example, the admin can grant access.
I could force the user to log out and back in, but then I'd have to rebuild the UI to enable/disable things in response
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Kevin Marois wrote: The security profile can change at runtime, for example, the admin can grant access. I have supplied a function to refresh/change the user profile from the main landing page (mainwindow) without having to log off. I always use the constructor and disable items. So I'm no use to you with the CanExecute issue.
Kevin Marois wrote: I'd have to rebuild the UI to enable/disable things in response Now that on the other hand would be irritating.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
Kevin Marois wrote: The problem is that the CanExecute doesn't fire until I actually click on a menu bar.
As far as I can see, that would be the expected behaviour. The system doesn't need to know whether the menu item is enabled or not until the menu is shown, so I wouldn't expect it to call CanExecute for the menu's command until you click on the button to show the menu.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
In wpf mvvm, a checkbox is set in a custom popup. If there is another datagrid below the popup control, clicking the checkbox will pass the mouse click event to the lower layer. How to control the mouse click event in the custom popup at the upper layer, so that the click event is not passed to the bottom layer, thank you
|
|
|
|
|
The scenario you describe (custom popup) has nothing to do with event tunneling or bubbling. Whatever is getting "passed", it's not an "event".
What is a "layer"? One can't confuse the logical and the physical when trying to solve a problem.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Here's my code:
<DataGridTextColumn Header="PO Cost"
Binding="{Binding Total, StringFormat=C, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Width="100"
IsReadOnly="True">
<pre>
<DataGridTextColumn.HeaderStyle>
<Style TargetType="DataGridColumnHeader">
<Setter Property="HorizontalContentAlignment" Value="Right" />
</Style>
</DataGridTextColumn.HeaderStyle>
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="HorizontalAlignment" Value="Right" />
</Style>
</DataGridTextColumn.ElementStyle>
The problem is that the header style changes the way the header looks. Here is a screen shot: https://1drv.ms/u/s!AjBmoYAYz_v2ghvO9qNjDcOFvZGh?e=feNnPO
Any ideas what's wrong?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Just spent 10 minutes trying to get the syntax for HeaderTextAlignment before I realised I used Telerik grids for that.
In the past I have created the header style for ALL columns and then based the right align on that custom header. Ghu knows what they have done to the built in style.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
Looks like you've got a custom header style defined somewhere, which is not being picked up as the base style for your right-aligned style.
If you can find the custom header style, you might be able to use BasedOn to fix the right-aligned style:
Style.BasedOn Property (System.Windows) | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi!
I am trying to make a window that when it starts, takes up the entire width of the screen, regardless of resolution.
I have tried to set the Width to 100% and to bind it to the primary screen width
Width="{Binding SystemParameters.PrimaryScreenWidth}">
But neither worked
Anyone have any idea on how to do it?
Have a nice day
|
|
|
|
|
|
|
Hi!
SO close
It gives a very small gap between the screen edge and the window.
I took a screenshot of the screen so that I could zoom in and check how many pixels there was between the window and the screen.
It's around 8 pixels gap on the right side.
And even if I set Left and Top to 0, I get one pixel from the top and 8 from the Left.
Here is the XML code for the window that I have now:
<Window x:Class="Sales.Menu"
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:Sales"
mc:Ignorable="d"
Top="0"
Left="0"
Title="Menu" Height="450" Width="{Binding Source={x:Static SystemParameters.PrimaryScreenWidth}}"
>
<!--The rectangle below is just a test-->
<Grid>
<Rectangle Width="10"></Rectangle>
</Grid>
</Window>
I would want it go to to the edge and there to be no gaps.
Thanks for the help so far
Have a nice day!
Thinking of getting a new IDE!
|
|
|
|
|
|
Create a (dummy) maximized window in the background and copy it's properties (e.g. width) to your actual "centered" window.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
I was about to try Gerry's suggestion when I decided to test retriving the screen width with code and set the window size to it.
It worked, but I wonder, is there not a way to do this without using code in WPF?
Here is the code I used if someone is interested:
this.Width = System.Windows.SystemParameters.PrimaryScreenWidth+2; Note that +2 is there since the Windows Left parameter in the XML are set to -2, had to compensate for that or I get a small gap to the right.
I put it right below the "InitializeComponent();" call.
Have a nice day!
Thinking of getting a new IDE!
|
|
|
|
|
|
I have a DataGrid with a couple of DataGridTemplateColumns .
When I try to hit the Enter-key on my keyboard there is no new row created in the DataGrid.
I have other DataGrids with columns which are not DataGridTemplateColumns and I can then create new rows by hitting the Enter-key. So I assume the DataGridTemplateColumns in some way causing the problem.
I have made a reproducible code and I have made it public in this GIT-Gist.
* I use Fody PropertyChanged to handle all the INotificationPropertyChanged in my view models.
* The code should just be copy-and-paste.
The bindings between the View and the ViewModels also don't seem to work :S
But if you uncomment the row in the ViewModel's construcotor (please see line 60 in the MainWindow.xaml.cs), a new row in the DataGrid will be created. With this row, the bindings works as expected. I cannot understand why.
Here is the XAML-code. It maybe enough for you with only the XAML-code to solve this problem.
<Window x:Class="WpfApp1.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:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.DataContext>
<local:ViewModel />
</Window.DataContext>
<DataGrid ItemsSource="{Binding Rows}" AutoGenerateColumns="False" CanUserAddRows="True" Margin="0,50,0,0">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Browse">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Command="{Binding Browse}" Content="..." Width="40" Margin="6,0,6,0" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Width="300" Header="Path" IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding Path, Mode=OneWay}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Width="100" Header="Slider">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Slider Value="{Binding Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Minimum="1" Maximum="50" Margin="6,0,6,0" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Binding="{Binding Value}" Header="Value" IsReadOnly="True" />
</DataGrid.Columns>
</DataGrid>
</Window>
modified 8-Oct-19 7:33am.
|
|
|
|
|
Can't think of too many examples that use buttons and sliders in a data grid; data sources called "path" and "value"; and columns that are read-only. Worlds in collision.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
The code I gave, is only an example how to reproduce the problem.
A real-life example of a button, textboxes and a slide is irrelevant.
My actual code contains of a button, a textbox, two numeric up down controls and a date picker in each row. All columns, except the textbox, are DataGridTemplateColumns.
Is there a solution to my problem?
|
|
|
|