Shock
Shock
CC#
Created by Shock on 11/13/2024 in #help
WPF local: when using Dependency Injection
Hello, My WPF app is utilizing dependency injection following https://achraf-chennan.medium.com/net-core-dependency-injection-for-wpf-core-62dc282690f8 (which removes StartupUri from the App.xaml file). When I'm attemping to utilize data binding, but local:SessionConverter isn't being recognize and I'm not understanding how to work around it as I'm unable to set the DataContext in the main window due to the parameters.
public enum Data
{
Data1,
Data2,
Data3
}
public partial class MainWindow : Window
{
private readonly ICustomWrapper _customWrapper;
public MainWindow(ICustomWrapper customWrapper)
{
InitializeComponent();
}
private Data _data;
public Data data
{
get=> _data;
set
{
_data = value;
MessageBox.Show("The selected datum is: " + "value.ToString());
}

public class SessionConverter : IValueConverter
{
public object? Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value?.Equals(parameter);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value?.Equals(true) == true ? parameter : Binding.DoNothing;
}
}
public enum Data
{
Data1,
Data2,
Data3
}
public partial class MainWindow : Window
{
private readonly ICustomWrapper _customWrapper;
public MainWindow(ICustomWrapper customWrapper)
{
InitializeComponent();
}
private Data _data;
public Data data
{
get=> _data;
set
{
_data = value;
MessageBox.Show("The selected datum is: " + "value.ToString());
}

public class SessionConverter : IValueConverter
{
public object? Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value?.Equals(parameter);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value?.Equals(true) == true ? parameter : Binding.DoNothing;
}
}
The .xaml code looks like the following (button data removed)
<Window x:Class="DataTest.MainWindow"
xmlns:local="clr-namespace:DataTest"/>
<Window.Resources>
<local:SessionConverter x:Key="SessionConverter"/>
</Window.Resources>
<Grid>
<StackPanel>
<RadioButton>
</RadioButton>
</StackPanel>
</Grid>
<Window x:Class="DataTest.MainWindow"
xmlns:local="clr-namespace:DataTest"/>
<Window.Resources>
<local:SessionConverter x:Key="SessionConverter"/>
</Window.Resources>
<Grid>
<StackPanel>
<RadioButton>
</RadioButton>
</StackPanel>
</Grid>
Could anyone point me in the right direction here?
14 replies
CC#
Created by Shock on 11/7/2024 in #help
Out Parameter Question
I think this should be simple, but I am coming up blank on a method call with an out parameter. (The example below is basic but my actual code requires the parameters) File1.Cs
class Example
{
public void Position(int row, int col, out string txt)
{
StringBuilder Data = new StringBuilder(20);
UInt64 f = (UInt64)(row * col);
txt=Data.ToString();
return f;
}
}
class Example
{
public void Position(int row, int col, out string txt)
{
StringBuilder Data = new StringBuilder(20);
UInt64 f = (UInt64)(row * col);
txt=Data.ToString();
return f;
}
}
If I am trying to call the Position Method in File2.Cs
namespace Example
{
class Example2
{
public void Call()
{
Example p = new Example();
p.Position(1,2,???);
namespace Example
{
class Example2
{
public void Call()
{
Example p = new Example();
p.Position(1,2,???);
What do I put for the last parameter on p.Position?
16 replies