Elio
Elio
CC#
Created by Elio on 6/17/2024 in #help
Access dependency property from a viewmodel WPF
HI, i'm using WPF and MVVM pattern. i've created a DependencyProperty IsEditable and how do i access this one from my viewmodel to bind it to CanExecute for my command.
public class ListingUserControl : UserControl
{
#region Properties
public bool IsEditable
{
get => (bool)GetValue(IsEditableProperty);
set => SetValue(IsEditableProperty, value);
}

public static readonly DependencyProperty IsEditableProperty =
DependencyProperty.Register(
"IsEditable",
typeof(bool),
typeof(ListingUserControl),
new PropertyMetadata(true));
#endregion

}
public class ListingUserControl : UserControl
{
#region Properties
public bool IsEditable
{
get => (bool)GetValue(IsEditableProperty);
set => SetValue(IsEditableProperty, value);
}

public static readonly DependencyProperty IsEditableProperty =
DependencyProperty.Register(
"IsEditable",
typeof(bool),
typeof(ListingUserControl),
new PropertyMetadata(true));
#endregion

}
private bool CanExecuteCommand() { return IsEditable; }
private bool CanExecuteCommand() { return IsEditable; }
4 replies
CC#
Created by Elio on 5/16/2024 in #help
WPF Datagrid Extended
No description
1 replies
CC#
Created by Elio on 5/2/2024 in #help
Visualizer XAML
Hi, i've created my own ToggleButton Control and i was wondering how to remove the Cannot find resource named <Resource name>. error in the xaml vizualizer ? Because it can display my control on runtime and even in xaml vizualizer but it bother me to see this ghost error. here the code if it can help : https://paste.mod.gg/zaxjipozqilv/4
2 replies
CC#
Created by Elio on 4/26/2024 in #help
✅ JSON Deserialize Derived Class
Hi, i'm struggling to deserialize my object with the Newtonsoft.Json Librairy. I've a collection of Step named Steps which can be a Stepspecial or Stepnormal. I'm trying to write my JsonConverter to deserialize the collection of Step but when i try to deserialize i keep getting the stack overflow error because jObject.ToObject call back ReadJson :
public class StepConverterJSON : JsonConverter<Step>
{
#region Properties
public override bool CanWrite => false;
#endregion

#region Override Methods
public override void WriteJson(JsonWriter writer, Step? value, JsonSerializer serializer) { throw new NotImplementedException(); }

public override Step? ReadJson(JsonReader reader, Type objectType, Step? existingValue, bool hasExistingValue, JsonSerializer serializer)
{
// Load a JObject from the JsonReader
JObject jObject = JObject.Load(reader);

if(jObject["Message"] != null)
{
// Use the new serializer to deserialize the object
StepSpecial? stepSpecial = serializer.Deserialize<StepSpecial>(reader);
return stepSpecial;
}
else
{
StepNormal? stepNormal = jObject.ToObject<StepNormal>(serializer);
//StepNormal? stepNormal = serializer.Deserialize<StepNormal>(reader);
return stepNormal;
}
}
#endregion
}
public class StepConverterJSON : JsonConverter<Step>
{
#region Properties
public override bool CanWrite => false;
#endregion

#region Override Methods
public override void WriteJson(JsonWriter writer, Step? value, JsonSerializer serializer) { throw new NotImplementedException(); }

public override Step? ReadJson(JsonReader reader, Type objectType, Step? existingValue, bool hasExistingValue, JsonSerializer serializer)
{
// Load a JObject from the JsonReader
JObject jObject = JObject.Load(reader);

if(jObject["Message"] != null)
{
// Use the new serializer to deserialize the object
StepSpecial? stepSpecial = serializer.Deserialize<StepSpecial>(reader);
return stepSpecial;
}
else
{
StepNormal? stepNormal = jObject.ToObject<StepNormal>(serializer);
//StepNormal? stepNormal = serializer.Deserialize<StepNormal>(reader);
return stepNormal;
}
}
#endregion
}
Any idea how to solve this and write a good ReadJson method ? i've thought about the populate method but not sure this is the good way of doing it.
61 replies
CC#
Created by Elio on 4/17/2024 in #help
Dependency property converter
Hi, i'm using WPF and i wanted to know if there is a way to use dependency property in a converter ? in order to write this kind of line :
<Grid>
<Grid.Resources>
<converter:UnitConverter x:Key="UnitConverter" ObservableUnit="{Binding ObsUnit}"/>
</Grid.Resources>
</Grid>
<Grid>
<Grid.Resources>
<converter:UnitConverter x:Key="UnitConverter" ObservableUnit="{Binding ObsUnit}"/>
</Grid.Resources>
</Grid>
currently i've tried this :
public class UnitConverter : DependencyObject, IValueConverter
{
#region Properties
public ObservableUnit ObservableUnit
{
get => (ObservableUnit)GetValue(ObservableUnitProperty);
set => SetValue(ObservableUnitProperty, value);
}
#endregion

#region Fields
public static readonly DependencyProperty ObservableUnitProperty =
DependencyProperty.Register("ObservableUnit", typeof(ObservableUnit), typeof(UnitConverter));
#endregion
}
public class UnitConverter : DependencyObject, IValueConverter
{
#region Properties
public ObservableUnit ObservableUnit
{
get => (ObservableUnit)GetValue(ObservableUnitProperty);
set => SetValue(ObservableUnitProperty, value);
}
#endregion

#region Fields
public static readonly DependencyProperty ObservableUnitProperty =
DependencyProperty.Register("ObservableUnit", typeof(ObservableUnit), typeof(UnitConverter));
#endregion
}
but it doesn't set my property.
1 replies
CC#
Created by Elio on 4/16/2024 in #help
Binding error Datagrid WPF
No description
1 replies
CC#
Created by Elio on 4/12/2024 in #help
✅ "Animate" an image along a axis
No description
4 replies
CC#
Created by Elio on 4/4/2024 in #help
SQLITE EFcore saving value
Hi, i'm working on a project which have a SQLITE database. I'm using EFcore to managed it. I want to know if there is a way to automatically add/remove/update by tracking or idk all the variable in my list Widths. Basically i want to call a methods Save that will add thickness if not added or add/remove/update elements in width a if thickness i already in the database.
public class Thickness
{
#region Properties
[Key]
public long Id { get; set; }

[Required]
public long MaterialId { get; set; }

[Required]
public double Value { get; set; }

public List<Width> Widths { get; set; } = new List<Width>();
}
public class Thickness
{
#region Properties
[Key]
public long Id { get; set; }

[Required]
public long MaterialId { get; set; }

[Required]
public double Value { get; set; }

public List<Width> Widths { get; set; } = new List<Width>();
}
[Table("Width")]
public class Width
{
#region Properties
[Key]
public long Id { get; set; }

[Required]
public long ThicknessId { get; set; }

[Required]
public double Value { get; set; }
}
[Table("Width")]
public class Width
{
#region Properties
[Key]
public long Id { get; set; }

[Required]
public long ThicknessId { get; set; }

[Required]
public double Value { get; set; }
}
57 replies
CC#
Created by Elio on 3/19/2024 in #help
Shitfting Image WPF
No description
1 replies
CC#
Created by Elio on 3/15/2024 in #help
Custom ToggleButon WPF
https://paste.mod.gg/siztgxijeavn/1 Hello, i'm trying to make my own togglebutton because i want it to have the property IscheckedLeft that allow me to easily switch the side of the checked value of my button. I've almost done it but i can't find a way to change my storyboard depends of IscheckedLeft. Basically i would like to Set this if IscheckedLeft = false
<ThicknessAnimation
Storyboard.TargetName="Thumb"
Storyboard.TargetProperty="Margin"
To="0 0 39 0"
Duration="0:0:0.2" />
<ThicknessAnimation
Storyboard.TargetName="Thumb"
Storyboard.TargetProperty="Margin"
To="0 0 39 0"
Duration="0:0:0.2" />
and Set this if IscheckedLeft = true
<ThicknessAnimation
Storyboard.TargetName="Thumb"
Storyboard.TargetProperty="Margin"
To="39 0 0 0"
Duration="0:0:0.2" />
<ThicknessAnimation
Storyboard.TargetName="Thumb"
Storyboard.TargetProperty="Margin"
To="39 0 0 0"
Duration="0:0:0.2" />
My problem there is if i use a converter the following error is triggered "Cannot freeze this Storyboard timeline tree for use across threads". Have you any idea how i could do this ?
1 replies
CC#
Created by Elio on 3/11/2024 in #help
✅ Deploying WPF APP
Hi, i'm a bit lost with all the informations i've found like .net Framework, .net Runtime, Publish ClickOnce etc. I'd like to have some help to deploy my wpf app. To summ up i've developped an wpf app which : - Use .Net 8 Framework - Target Windows 10 .0.17763 This app is destinated to be set on a computer which isn't connected to Internet by using a usb key. So basically i thought about an installer which include the framework if needed to download and have all the stuff related to my app to set everything on the offline computer. How i'm am supposed to do ? Do i need to create an installer by myself or the publish tool on visual studio is supposed to work if well configured ?
49 replies
CC#
Created by Elio on 1/31/2024 in #help
MVVM TOOLKIT SetProtperty
Hello, i'm trying to had a decimal number in my textbox but i can't add a . or , to write my decimal number. here is the declaration of my property that i bind to my textbox.
private readonly SymmetricRoll _symmetricRoll;
public double RollPosition
{
get => _symmetricRoll.RollPosition;
set => SetProperty(_symmetricRoll.RollPosition, value, _symmetricRoll, (symmRoll, newValue) => symmRoll.RollPosition = newValue);
}
private readonly SymmetricRoll _symmetricRoll;
public double RollPosition
{
get => _symmetricRoll.RollPosition;
set => SetProperty(_symmetricRoll.RollPosition, value, _symmetricRoll, (symmRoll, newValue) => symmRoll.RollPosition = newValue);
}
Do i need to link my textbox to a string and then i parse this string to affect the value to RollPosition ?
7 replies
CC#
Created by Elio on 1/30/2024 in #help
✅ RelayCommand CanExecute MVVM
Hi, I'm using this nuget CommunityToolkit.Mvvm.Input to add my relaycommand. i've set CanExecute this way => AddThickCommand = new RelayCommand(AddThickCommand_Execute, () => CanAddThickness); My problem there is that canexecute is trigger only when i declare AddThickCommand and canexecute is never raised again even if the boolean CanAddThickness change. I'd like to update canexecute each time CanAddThickness change to enable or not the button. Any idea why this don't work with this package ?
10 replies
CC#
Created by Elio on 1/16/2024 in #help
✅ WPF IEnumerable PropertyChanged()
Hi, Any idea why my IEnumerable variable isn't refreshed even when the Onpropertychanged is triggered ? Here is the code : https://paste.mod.gg/xucezzpuabkj/3 note that the viewmodel is correctly bind to the view.
4 replies
CC#
Created by Elio on 12/14/2023 in #help
✅ WPF Datagrid colums width
No description
12 replies
CC#
Created by Elio on 9/6/2023 in #help
❔ WPF Validation
Hi, i've created a UserViewmodel which contains 2 properties, name and age. I've setup all the IDataErrorInfo that i needed in my viewmodel (age < 100 for exemple). I use WPF and i'd like to know if it is possible to bind the propertie age to a ModalDialog which contains a texbox to get back the age from the user. And my problem there is that i need to send UserViewmodel to keep the Validation model that i've set but it means that i can't reuse ModalDialog for another viewmodel for example FamilyViewmodel with properties ChildrenNumber.
2 replies
CC#
Created by Elio on 9/5/2023 in #help
WPF Validation
7 replies
CC#
Created by Elio on 8/31/2023 in #help
❔ Display error message if value out of limit
Hi, i'm using wpf with mvvm pattern and i'd like to know if it's good to do this in order to display a message error if the value enter isn't good :
public class StepNormalViewModel : StepViewModel
{
private readonly StepNormal _stepNormal;

private double _aV;
public double AV
{
get => _aV;
set
{
if(StepCheck.CheckAV(_aV))
{
_stepNormal.AV = _aV;
_aV = value;
OnPropertyChanged();
}
else
{
//*Display my Error forms*
}
}
}
}
public class StepNormalViewModel : StepViewModel
{
private readonly StepNormal _stepNormal;

private double _aV;
public double AV
{
get => _aV;
set
{
if(StepCheck.CheckAV(_aV))
{
_stepNormal.AV = _aV;
_aV = value;
OnPropertyChanged();
}
else
{
//*Display my Error forms*
}
}
}
}
6 replies
CC#
Created by Elio on 8/9/2023 in #help
✅ Singleton Class
Do you know if there is a way to call a method each time i retrieve my singleton class this way : services.GetRequiredService<MaterialDetailsViewModel>() I want to reset 1 variable each time i call this singleton with GetRequiredService
6 replies
CC#
Created by Elio on 7/4/2023 in #help
✅ WPF Datagrid Select
Hi, i'm trying to change the style of each row depends of the datatype. Currently my code seems to work, i'm able to select the style for each row by using the selector. But here i have a problem in the style of my row :
<Style x:Key="StepCommentRowStyle" TargetType="DataGridRow">
<Setter Property="Background" Value="{StaticResource YellowGradientPrimaryColor}" />
<Setter Property="Height" Value="25" />
> <Setter Property="Template">
> <Setter.Value>
> <ControlTemplate TargetType="DataGridRow">
> <Grid Background="{TemplateBinding Background}">
> <Image
> Width="20"
> Height="20"
> Source="{StaticResource ICON_COMMENT_20x20}" />
> <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
> </Grid>
> </ControlTemplate>
> </Setter.Value>
> </Setter>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="Blue" />
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="StepCommentRowStyle" TargetType="DataGridRow">
<Setter Property="Background" Value="{StaticResource YellowGradientPrimaryColor}" />
<Setter Property="Height" Value="25" />
> <Setter Property="Template">
> <Setter.Value>
> <ControlTemplate TargetType="DataGridRow">
> <Grid Background="{TemplateBinding Background}">
> <Image
> Width="20"
> Height="20"
> Source="{StaticResource ICON_COMMENT_20x20}" />
> <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
> </Grid>
> </ControlTemplate>
> </Setter.Value>
> </Setter>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="Blue" />
</Trigger>
</Style.Triggers>
</Style>
if i remove the template part, the row can be selected when i click on it but when i add the template setter part it seems to remove the selectability of the row when i click on it. Have you any idea how to resolve this problem ? i supposed that i override the default template but i dont know how to keep the selectable part
8 replies