|
I beleive I finally have it working! This was mainly about me learning how to create Custome Controls. I appreciate all your help. I learned a lot.
Here's the finiished product!
Generic.xaml
<Style TargetType="{x:Type local:MaroisHyperlink}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<TextBlock>
<Hyperlink x:Name="hyperLink"
Foreground="{Binding Foreground, RelativeSource={RelativeSource TemplatedParent}}"
TextDecorations="{Binding TextDecorations, RelativeSource={RelativeSource TemplatedParent}}">
<TextBlock Text="{Binding LinkText,
RelativeSource={RelativeSource TemplatedParent}}"/>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<i:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType=Control}, Path=LinkClickedCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Hyperlink>
</TextBlock>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="hyperLink" Property="TextDecorations" Value="{Binding TextDecorations, RelativeSource={RelativeSource TemplatedParent}}"/>
<Setter TargetName="hyperLink" Property="Foreground" Value="{Binding HoverBrush, RelativeSource={RelativeSource TemplatedParent}}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Code Behind
public class MaroisHyperlink : ControlBase
{
#region Routed Events
#region LinkClickedEvent
public static readonly RoutedEvent LinkClickedEvent =
EventManager.RegisterRoutedEvent("LinkClicked",
RoutingStrategy.Bubble,
typeof(RoutedEventHandler),
typeof(MaroisHyperlink));
public event RoutedEventHandler LinkClicked
{
add { AddHandler(LinkClickedEvent, value); }
remove { RemoveHandler(LinkClickedEvent, value); }
}
private void RaiseLinkClickedEvent()
{
RoutedEventArgs args = new RoutedEventArgs(LinkClickedEvent);
RaiseEvent(args);
}
#endregion
#endregion
#region DP's
#region DP TextDecorations
public static readonly DependencyProperty TextDecorationsProperty =
Inline.TextDecorationsProperty.AddOwner(typeof(MaroisHyperlink));
public TextDecorationCollection TextDecorations
{
get { return (TextDecorationCollection)GetValue(TextDecorationsProperty); }
set { SetValue(TextDecorationsProperty, value); }
}
#endregion
#region DP HoverBrush
public static readonly DependencyProperty HoverBrushProperty =
DependencyProperty.Register("HoverBrush",
typeof(SolidColorBrush),
typeof(MaroisHyperlink),
new PropertyMetadata(new SolidColorBrush(Colors.Green)));
public SolidColorBrush HoverBrush
{
get { return (SolidColorBrush)GetValue(HoverBrushProperty); }
set { SetValue(HoverBrushProperty, value); }
}
#endregion
#region DP LinkText
public static readonly DependencyProperty LinkTextProperty =
DependencyProperty.Register("LinkText",
typeof(string),
typeof(MaroisHyperlink),
new PropertyMetadata("MaroisHyperlink"));
public string LinkText
{
get { return (string)GetValue(LinkTextProperty); }
set { SetValue(LinkTextProperty, value); }
}
#endregion
#endregion
#region Commands
private ICommand? _LinkClickedCommand;
public ICommand LinkClickedCommand
{
get
{
if (_LinkClickedCommand == null)
_LinkClickedCommand = new RelayCommand(LinkClickedExecuted);
return _LinkClickedCommand;
}
}
#endregion
#region CTOR
static MaroisHyperlink()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(MaroisHyperlink),
new FrameworkPropertyMetadata(typeof(MaroisHyperlink)));
}
#endregion
#region Private Methods
private void LinkClickedExecuted()
{
RaiseLinkClickedEvent();
}
#endregion
}
Usage, with overriding style
<Window x:Class="Marois.Framework.Core.WPF.Controls.Demo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:marois="clr-namespace:Marois.Framework.Core.WPF.Controls;assembly=Marois.Framework.Core.WPF.Controls"
mc:Ignorable="d"
WindowStartupLocation="CenterScreen"
Title="Marois Controls Demo"
Height="450"
Width="800">
<Window.Resources>
<Style TargetType="{x:Type marois:MaroisHyperlink}">
<Setter Property="HoverBrush" Value="OliveDrab"/>
<Setter Property="Foreground" Value="Cyan"/>
<Setter Property="FontSize" Value="30"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Foreground" Value="BlanchedAlmond" />
<Setter Property="TextDecorations" Value="Underline" />
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="LightGray" />
<Setter Property="TextDecorations" Value="None" />
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<StackPanel Orientation="Vertical">
<CheckBox x:Name="checkBox"
Content="Enabled"
IsChecked="True"
Margin="5"/>
<marois:MaroisHyperlink x:Name="link"
Margin="5"
IsEnabled="{Binding ElementName=checkBox, Path=IsChecked}"
HorizontalAlignment="Left"
VerticalAlignment="Top">
<i:Interaction.Triggers>
<i:EventTrigger EventName="LinkClicked">
<i:InvokeCommandAction Command="{Binding MaroisLinkClickedCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</marois:MaroisHyperlink>
</StackPanel>
</Grid>
</Window>
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Following this SO article, I'm trying to create a relay command that takes parameters:
<ctrls:MaroisHyperlink LinkText="Forgot Password?"
Foreground="SteelBlue"
Margin="30,0,0,0"
Height="20">
<i:Interaction.Triggers>
<i:EventTrigger EventName="LinkClicked">
<i:InvokeCommandAction Command="{Binding ForgotPasswordClickedCommand}"
CommandParameter="True"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ctrls:MaroisHyperlink>
Here's my RelayCommand<t> class:
namespace Marois.Framework.Core.Utilities
{
public class RelayCommand<T> : ICommand
{
private readonly Action<T> execute;
private readonly Func<T, bool> canExecute;
public RelayCommand(Action<T> execute)
: this(execute, null)
{
}
public RelayCommand(Action<T> execute, Func<T, bool> canExecute)
{
ArgumentNullException.ThrowIfNull(execute);
this.execute = execute;
this.canExecute = canExecute;
this.RaiseCanExecuteChangedAction = RaiseCanExecuteChanged;
SimpleCommandManager.AddRaiseCanExecuteChangedAction(ref RaiseCanExecuteChangedAction);
}
~RelayCommand()
{
RemoveCommand();
}
public void RemoveCommand()
{
SimpleCommandManager.RemoveRaiseCanExecuteChangedAction(RaiseCanExecuteChangedAction);
}
bool ICommand.CanExecute(object? parameter)
{
return canExecute((T)parameter);
}
public void Execute(object? parameter)
{
if (CanExecute(parameter))
{
execute((T)parameter);
}
}
public bool CanExecute(object? parameter)
{
return canExecute == null ? true : canExecute((T)parameter);
}
public void RaiseCanExecuteChanged()
{
var handler = CanExecuteChanged;
if (handler != null)
{
handler(this, new EventArgs());
}
}
private readonly Action RaiseCanExecuteChangedAction;
public event EventHandler CanExecuteChanged;
}
public static class SimpleCommandManager
{
private static List<Action> _raiseCanExecuteChangedActions = new List<Action>();
public static void AddRaiseCanExecuteChangedAction(ref Action raiseCanExecuteChangedAction)
{
_raiseCanExecuteChangedActions.Add(raiseCanExecuteChangedAction);
}
public static void RemoveRaiseCanExecuteChangedAction(Action raiseCanExecuteChangedAction)
{
_raiseCanExecuteChangedActions.Remove(raiseCanExecuteChangedAction);
}
public static void AssignOnPropertyChanged(ref PropertyChangedEventHandler propertyEventHandler)
{
propertyEventHandler += OnPropertyChanged;
}
private static void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName != "CanExecute")
{
RefreshCommandStates();
}
}
public static void RefreshCommandStates()
{
for (var i = 0; i < _raiseCanExecuteChangedActions.Count; i++)
{
var raiseCanExecuteChangedAction = _raiseCanExecuteChangedActions[i];
if (raiseCanExecuteChangedAction != null)
{
raiseCanExecuteChangedAction.Invoke();
}
}
}
}
}
and here's the VM
private ICommand? _ForgotPasswordClickedCommand;
public ICommand ForgotPasswordClickedCommand
{
get
{
if (_ForgotPasswordClickedCommand == null)
_ForgotPasswordClickedCommand = new RelayCommand<bool>(p => ForgotPasswordLinkClickedExecuted(p), a => ForgotPasswordCanExecute(a));
return _ForgotPasswordClickedCommand;
}
}
private bool ForgotPasswordCanExecute(bool args)
{
return true;
}
private void ForgotPasswordLinkClickedExecuted(bool args)
{
}
When I set the parameter type to Object then it works fine. But if I set it to Bool, as above, then I get the following exception:
'Unable to cast object of type 'System.String' to type 'System.Boolean'.'
I have an implementation of this a WPF .Net Framework and it works fine. But in the .Net Core app I get the error.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
I have a WPF app with a Login window. I'd like to add a "Forgor Password?" link in it. The question is, how would I implement it?
The app has an Employees page. I could put something there that could be checked when the link is clicked.
Another option would be to send an email to the user, but then what?
Any ideas?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
|
I'm trying to create what I thought would be a simple custom control to implement a hyperlink.
This all works in WPF .Net Framework, but in .Net Core I have 2 problems. First, here's the code:
XAML
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MaroisHyperlink"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors">
<pre>
<Style TargetType="{x:Type local:MaroisHyperlink}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<TextBlock>
<Hyperlink>
<TextBlock Text="{Binding LinkText}"/>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<i:InvokeCommandAction Command="{Binding LinkClickedCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Hyperlink>
</TextBlock>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Code Behind
using Marois.Framework.Core.Utilities;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace MaroisHyperlink
{
public class MaroisHyperlink : Control
{
#region Commands
private ICommand? _LinkClickedCommand;
public ICommand LinkClickedCommand
{
get
{
if (_LinkClickedCommand == null)
_LinkClickedCommand = new RelayCommand(LinkClickedExecuted, LinkClickedCanExecute);
return _LinkClickedCommand;
}
}
#endregion
#region DP LinkText
public static readonly DependencyProperty LinkTextProperty =
DependencyProperty.Register("LinkText",
typeof(string),
typeof(MaroisHyperlink),
new PropertyMetadata("", new PropertyChangedCallback(OnLinkTextChanged)));
public string LinkText
{
get { return (string)GetValue(LinkTextProperty); }
set { SetValue(LinkTextProperty, value); }
}
private static void OnLinkTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
}
#endregion
#region LinkClickedEvent
public static readonly RoutedEvent LinkClickedEvent =
EventManager.RegisterRoutedEvent("LinkClicked",
RoutingStrategy.Bubble,
typeof(RoutedEventHandler),
typeof(MaroisHyperlink));
public event RoutedEventHandler LinkClicked
{
add { AddHandler(LinkClickedEvent, value); }
remove { RemoveHandler(LinkClickedEvent, value); }
}
private void RaiseLinkClickedEvent()
{
RaiseEvent(new RoutedEventArgs(LinkClickedEvent));
}
#endregion
#region CTOR
static MaroisHyperlink()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(MaroisHyperlink),
new FrameworkPropertyMetadata(typeof(MaroisHyperlink)));
}
#endregion
#region Private Methods
private bool LinkClickedCanExecute()
{
return IsEnabled;
}
private void LinkClickedExecuted()
{
RaiseLinkClickedEvent();
}
#endregion
}
}
Window
<Window x:Class="HyperlinkDemo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:link="clr-namespace:MaroisHyperlink;assembly=MaroisHyperlink"
WindowStartupLocation="CenterScreen"
mc:Ignorable="d"
Title="MainWindow"
Height="300"
Width="500">
<pre>
<Grid>
<link:MaroisHyperlink LinkText="Click This Link!"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="16"/>
</Grid>
Problems
1. The LinkText is not appearing. I get no binding errors, but when I run it, there's nothing showing. If I set the inner TextBox's text to something, then it shows up.
<TextBlock>
<pre>
<Hyperlink>
<TextBlock Text="THIS SHOWS UP"/>
</Hyperlink>
2. This doesn't compile:
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<i:InvokeCommandAction Command="{Binding LinkClickedCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
I get
The type 'Interaction' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.
I have package "Microsoft.Xaml.Behaviors.WPF (1.1.39") installed and my namespace is "xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
You're binding to a property defined in the code-behind of the control. But the DataContext isn't set anywhere, so it will be inherited from the parent. You'll need to use a TemplateBinding to bind to the control's properties:
<Style TargetType="{x:Type local:MaroisHyperlink}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<TextBlock>
<Hyperlink>
<TextBlock Text="{TemplateBinding LinkText}"/>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<i:InvokeCommandAction Command="{TemplateBinding LinkClickedCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Hyperlink>
</TextBlock>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
The Interaction markup looks correct to me. I can't see any reason for that not to compile, unless the NuGet package reference isn't loading correctly. It may be worth raising an issue on the GitHub project for that library[^].
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
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
|
|
|
|
|