|
LOL - I knew that. Wow, I need to take a break.
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
I have this in my theme file:
<Style TargetType="TextBlock">
<Setter Property="Foreground" Value="{DynamicResource textForegroundBrush}"/>
<Setter Property="FontSize" Value="14"/>
</Style>
Now, in a window I want to add additional settings
<Window.Resources>
<Style x:Key="headerTextStyle"
TargetType="TextBox">
<Setter Property="FontSize" Value="24"/>
</Style>
</Window.Resources>
Since the theme's style does not have a key, how do I base the window's style off the sstyle in the theme?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Try:
<Style x:Key="headerTextStyle" TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}">
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks, that did it.
I always thought using that would cause the child style to based off WPF's base style
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Hi!
I've searched for a couple of hours here and in other forums and at GitHub but couldn't find an answer.
I have a XML file and can read it in a DataTable and show that in a DataGrid. But I want to edit cells/values in the DataGrid and write the corrected values back to the XML file. It's easy for me to write the corrections to the DataTable and back to the XML file but how can I do the edit in the DataGrid ???
What I have so far with VisualStudio 2022:
using ...
namespace Gewicht
{
public partial class MainWindow : Window
{
public string[] dbFile = { @"H:\Daten\C#WPF\Gewicht\GewichtDaten.xml", @"H:\Daten\C#WPF\Gewicht\GewichtDaten.xsd" };
public DataTable dbDataTbl = new DataTable();
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
if (!System.IO.File.Exists(dbFile[0]) | !System.IO.File.Exists(dbFile[1]))
{
SystemSounds.Beep.Play();
MessageBox.Show("Die Datei" + Environment.NewLine + " " + dbFile[0] + Environment.NewLine + "und/oder" + Environment.NewLine + " " + dbFile[1] + Environment.NewLine + "fehlt." + Environment.NewLine + "Das Programm wird beendet.", "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
Environment.Exit(0);
}
DataGrid1.CanUserAddRows = false;
DataGrid1.CanUserDeleteRows = false;
OpenData();
}
private void DataGrid1_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
{
}
private void OpenData()
{
dbDataTbl.Columns.Clear();
dbDataTbl.Rows.Clear();
dbDataTbl = new DataTable("ich");
dbDataTbl.ReadXmlSchema(dbFile[1]);
dbDataTbl.ReadXml(dbFile[0]);
DataSet dataSet = new DataSet();
dataSet.ReadXml(dbFile[0]);
DataView dataView = new DataView(dataSet.Tables[0]);
DataGrid1.ItemsSource = dataView;
Style style = new Style();
style.TargetType = typeof(DataGridCell);
Setter setter = new Setter();
setter.Property = DataGridCell.ForegroundProperty;
setter.Value = Brushes.LightGray;
style.Setters.Add(setter);
DataGrid1.Columns[0].CellStyle = style;
style = new Style();
setter = new Setter();
setter.Property = DataGridCell.HorizontalContentAlignmentProperty;
setter.Value = HorizontalAlignment.Right;
DataGrid1.Columns[2].CellStyle = style;
}
}
}
What I also want:
- Data column 0 should be gray (done) and the values right aligned.
- Data column 2 should be right aligned and with number format "##0.0".
Thanks
|
|
|
|
|
|
I'm trying to figure out some alignment issues in one of my form.
Grid, containing stackpanels, containing grids. ...
It's an ItemTemplate, so I cannot see the design in Visual Studio, so I have to run and adjust the XAML and run again (some changes can be tested live, I know).
So, is there a way to see the bounded box around controls ?
I bodge something by wrapping controls inside Border and put a thickness of 1 for debugging.
But there must be a better way.
Thanks.
CI/CD = Continuous Impediment/Continuous Despair
|
|
|
|
|
|
Hi.
I have a request to change the look of our TogggleButton.
I'm not sure what to search for on the internet.
Instead of changing the background color when the TogggleButton is checked, I would need to have a line under it.
See imgur image : togglebutton - Album on Imgur
I know how to use ControlTemplates (with Storyboard and Coloranimation with the EnterActions and ExitActions) to change the background.
But I'm not sure how to do this for BorderThickness or if there is something better I could use.
Thanks for hints or tips or any "google search" I can do
CI/CD = Continuous Impediment/Continuous Despair
|
|
|
|
|
Use a one sided border:
<Border BorderThickness="0,0,0,2" BorderBrush="Black" >
<ToggleButton />
</Border>
Toggle the visibility of the border, the Brush (Transparent), or change the thickness - based on "Checked".
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Just found out we already have an in-house style for that in one of our dependency.
Thanks.
CI/CD = Continuous Impediment/Continuous Despair
|
|
|
|
|
I'm not certain what I have to google for.
I have Drawing images in an resource file like this :
<DrawingImage x:Key="FindIcon"/>
<DrawingImage x:Key="SearchIcon"/>
I can use them like this :
<Image Source="{StaticResource FindIcon}"/>
<Image Source="{StaticResource SearchIcon}"/>
Now, I want to be able to bind the image source and conditionally choose the image in the Code-Behind.
<Image Source="{Binding ChooseIcon}"/>
I'm not certain how I reference the image in the code ?
Is this a DrawingImage ? How do I load it in the code ?
public DrawingImage ChooseIcon
{
get
{
if (useFindIcon)
{
return ???;
}
else if (useSearchIcon)
{
return ???;
}
}
}
Thanks.
Max.
CI/CD = Continuous Impediment/Continuous Despair
|
|
|
|
|
The view-model shouldn't really know anything about your resources.
I'd suggest having an enum to represent the icon you want to display. Bind the source to that enum, and use a converter to convert the value to the relevant image.
Eg:
public enum ChooseIcon
{
Find,
Search,
}
public class YourViewModel
{
private ChooseIcon _chooseIcon;
public ChooseIcon ChooseIcon
{
get { return _chooseIcon; }
set { SetProperty(ref _chooseIcon, value); }
}
}
public class ChooseIconConverter : IValueConverter
{
public ImageSource FindIcon { get; set; }
public ImageSource SearchIcon { get; set; }
public object Convert (object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
switch ((ChooseIcon)value)
{
case ChooseIcon.Find: return FindIcon;
case ChooseIcon.Search: return SearchIcon;
default: return null;
}
}
public object ConvertBack (object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return Binding.DoNothing;
}
}
<Window.Resources>
<local:ChooseIconConverter
x:Key="ChooseIconConverter"
FindIcon="{StaticResource FindIcon}"
SearchIcon="{StaticResource SearchIcon}"
/>
</Window.Resources>
...
<Image Source="{Binding ChooseIcon, Mode=OneWay, Converter={StaticResource ChooseIconConverter}}" />
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks.
Will look at that.
I also bodge a hack by having 2 Image tags and add a Visibility binding.
CI/CD = Continuous Impediment/Continuous Despair
|
|
|
|
|
Awesome, it's working.
CI/CD = Continuous Impediment/Continuous Despair
|
|
|
|
|
I have an app in which the user can create invoices. There is a lot of data on an invoice:
Jobs
Ship To Address
Builders
Foremen
Foreman Phone
Vendors
Vendor Locations
Vendor Contacts
Vendor Contact Email
Vendor Contact Phone
Delivery Method (Will Call or Delivery)
Delivery Date
For Will Call
Picked Up By (employee)
Picked Up By Email
Picked Up By Email
Picked Up Location (From Vendor Locations)
Items (The items on the PO)
Much of this is just lists. Right now, some dat is not retrieved until it's needed. For example, Vendor Locations are not retrieved until a Vendor is selected.
The problem is that it's getting slow. There's a lot of logic being run when list items are picked.
So, should I only load data when it's needed, or load all data first then run any logic, like the Vendor Location? In other words, get all Vendors and all Vendor Locations, and only load the locations in the client one the initial data load is done?
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Both. Your app should anticipate the user's intention by the parts they're accessing and start asynchronous loads into observable collections that get bound when a particular user control ("view") gets loaded.
And / or you need revised stored procs / data views / filtering.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
I'm looking for a control that does the following.
When I do an action in my UI, I want to have a small window that slides in an out showing a small explanation text.
For example, I have a "copy" button that will put something on the clipboard.
I want to show a quick message that said "XYZ copied on the clipboard" the message will slide in and out of the main window.
I was looking at <popup> with an animation but I'm not sure it's what I want.
Or do you have a better alternative ?
Thanks.
CI/CD = Continuous Impediment/Continuous Despair
|
|
|
|
|
|
thanks, will have a look at it.
CI/CD = Continuous Impediment/Continuous Despair
|
|
|
|
|
it looks nice, even if it is a little bit "in your face".
Will experiment with look and feel.
Thanks again
CI/CD = Continuous Impediment/Continuous Despair
|
|
|
|
|
I have a button with a contextual menu attached to it, I want display the menu on the left click instead of the default right click.
I'm using a company wide "resource pack" that defines some style.
When I left click on the button to open the menu, the menu is drawn/rendered using the default windows style and the event/commands are not triggered.
When I right click on the button to open the menu, the menu is drawn/rendered using our styles and events/commands are working.
When I left click again the menu is drawn/rendered using our styles and event/commands are working
I'm not sure why the wrong menu is loaded once.
Any insights or things I might have missed ?
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MyCompany.Presentation;component/Themes/MyCompany.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<!-- ... -->
<Button Content="Right-Click Me!" Click="ButtonBase_OnClick">
<Button.ContextMenu>
<ContextMenu x:Name="MyContextMenu">
<MenuItem Header="a" IsCheckable="True" Command="{Binding DoACommand}" IsChecked="{Binding IsAChecked, Mode=OneWay}"/>
<MenuItem Header="b" IsCheckable="True" Command="{Binding DoBCommand}" IsChecked="{Binding IsBChecked, Mode=OneWay}"/>
</ContextMenu>
</Button.ContextMenu>
</Button>
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
if (MyContextMenu.ContextMenu != null)
MyContextMenu.ContextMenu.IsOpen = true;
}
CI/CD = Continuous Impediment/Continuous Despair
|
|
|
|
|
The WPF ContextMenu doesn't inherit the DataContext of its parent element. You need to set that explicitly for the bindings to work:
<ContextMenu x:Name="MyContextMenu" DataContext="{Binding PlacementTarget, RelativeSource={RelativeSource Self}}"> As for the styles not being applied when you left-click, have you tried different sequences? Try two left-clicks, or a right-click followed by a left click, to see whether the styles are applied the second time the menu appears, or only applied after a right-click.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Adding the datacontext does not change anything.
The menu loads correctly the first when I right click on the button; after that it loads correctly on the left click.
It's not urgent for now, I'm prototyping a UI. , but slightly annoying.
Thanks.
CI/CD = Continuous Impediment/Continuous Despair
|
|
|
|
|
I converted a .Net Framework WPF app to .Net Core. I now have 1800+ compilation errors.
It seems like 99% of them are
The name 'InitializeComponent' does not exist in the current context
Since this is so widespread, I'm going to assume something in the conversion broke this. I've been Googling and trying different things but no help.
I tried removing the obj & bin folders but that didn't solve anything.
Anyone have any ideas on this?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|