|
Had to add the RelativeSource:
<TextBlock Text="{Binding LinkText, RelativeSource={RelativeSource TemplatedParent}}"/>
However that doesn't seem to work in the command (For some reason the command code now compiles):
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<i:InvokeCommandAction Command="{TemplateBinding LinkClickedCommand, RelativeSource={RelativeSource TemplatedParent}}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
with
The property 'RelativeSource' was not found in type 'TemplateBindingExtension'.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
modified 30-Nov-22 12:05pm.
|
|
|
|
|
{TemplateBinding x} should be equivalent to {Binding x, RelativeSource={RelativeSource TemplatedParent}} .
The error is telling you that you can't set a RelativeSource on a TemplateBinding .
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I'd like to use paths for images so I can set the stroke & fill at runtime.
Is it possible to convert PNG or JPG files to XAML?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
modified 29-Nov-22 21:36pm.
|
|
|
|
|
There are a number of tools you can use to convert PNG/JPEG images to XAML. For example, Inkscape[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
How can I create a drop shadow effect all around an element?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Have you tried using a DropShadowEffect[^]?
NB: Avoid the DropShadowBitmapEffect , which has been obsolete since .NET Framework 4 because it was so slow.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Sorry, I should have given more info. Here's what I have so far:
<Border Grid.Row="1"
Margin="0,20,0,20"
VerticalAlignment="Center"
BorderBrush="Transparent"
Height="250">
<pre>
<Border.Effect>
<DropShadowEffect Color="LightGray"
ShadowDepth="7"
Direction="90"/>
</Border.Effect>
This puts the drop shadow along the top. I'd like it both at the top and bottom
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Try setting the ShadowDepth to 0 and playing with the BlurRadius instead.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I'm creating a theme with a base style for all controls:
<FontFamily x:Key="Font.Family.Default">Segoe UI</FontFamily>
<sys:Double x:Key="Font.Size.Header1">18</sys:Double>
<sys:Double x:Key="Font.Size.Header2">16</sys:Double>
<sys:Double x:Key="Font.Size.Header3">14</sys:Double>
<sys:Double x:Key="Font.Size.Normal">12</sys:Double>
<SolidColorBrush x:Key="TextBlock.Static.Background" Color="Transparent"/>
<SolidColorBrush x:Key="TextBlock.Static.Foreground" Color="DarkGray"/>
<Style x:Key="ControlBase" TargetType="{x:Type Control}">
<Setter Property="Control.FontSize" Value="{StaticResource Font.Size.Normal}"/>
<Setter Property="Control.FontFamily" Value="{StaticResource Font.Family.Default}"/>
<Setter Property="Control.HorizontalAlignment" Value="Center"/>
<Setter Property="Control.VerticalAlignment" Value="Center"/>
</Style>
<Style TargetType="{x:Type TextBlock}"
BasedOn="{StaticResource ControlBase}">
<Setter Property="Background" Value="{StaticResource TextBlock.Static.Background}"/>
<Setter Property="Foreground" Value="{StaticResource TextBlock.Static.Foreground}"/>
</Style>
I'm trying to use it like this:
<TextBlock Grid.Row="0"
Grid.Column="0"
Text="Test"
Margin="22,0,0,0"/>
The designer wont load, and when I run it I get
System.Windows.Markup.XamlParseException
Message='Initialization of 'System.Windows.Controls.TextBlock' threw an exception.' Line number '56' and line position '20'.
Inner Exception 1:
InvalidOperationException: Can only base on a Style with target type that is base type 'TextBlock'.
What's wrong here??
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
TextBlock doesn't inherit from class Control.
"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
|
|
|
|
|
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
|
|
|
|