frostfina
frostfina
CC#
Created by frostfina on 1/28/2023 in #help
❔ Generic method that takes in a struct and calls the correctly-typed method
Thanks
20 replies
CC#
Created by frostfina on 1/28/2023 in #help
❔ Generic method that takes in a struct and calls the correctly-typed method
Ah wait I didn't set the if like you though, that was the problem
20 replies
CC#
Created by frostfina on 1/28/2023 in #help
❔ Generic method that takes in a struct and calls the correctly-typed method
Mhh, weird
20 replies
CC#
Created by frostfina on 1/28/2023 in #help
❔ Generic method that takes in a struct and calls the correctly-typed method
That I did, that's what caused the error I sent
20 replies
CC#
Created by frostfina on 1/28/2023 in #help
❔ Generic method that takes in a struct and calls the correctly-typed method
It still complains that cannot convert from 'ref T' to 'ref OpenTK.Mathematics.Matrix4'. I think I'll go with the overload approach though, somehow it didn't cross my mind. Thank you :)
20 replies
CC#
Created by frostfina on 11/2/2022 in #help
Passing a string property to a command via a button CommandParameter in .NET 6
I mean I'm very knew to .NET and I've ever only had school experience, I'm far more experienced in other frameworks like Qt and it's pretty annoying to be stuck on such a simple problem. If I figure out the solution I'll make sure to share it
28 replies
CC#
Created by frostfina on 11/2/2022 in #help
Passing a string property to a command via a button CommandParameter in .NET 6
Yeah that's why I'm surprised that fails
28 replies
CC#
Created by frostfina on 11/2/2022 in #help
Passing a string property to a command via a button CommandParameter in .NET 6
Dunno if it's relevant, but here's the MainWindow's XAML as well
<Window x:Class="MeteoApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:MeteoApp"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.Resources>
<local:MainView x:Key="MainView"/>
</Window.Resources>
<Grid>
<ContentControl Content="{StaticResource MainView}"/>
</Grid>
</Window>
<Window x:Class="MeteoApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:MeteoApp"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.Resources>
<local:MainView x:Key="MainView"/>
</Window.Resources>
<Grid>
<ContentControl Content="{StaticResource MainView}"/>
</Grid>
</Window>
28 replies
CC#
Created by frostfina on 11/2/2022 in #help
Passing a string property to a command via a button CommandParameter in .NET 6
I just press the "Search" button to do my testing after changing the text in the TextBox
28 replies
CC#
Created by frostfina on 11/2/2022 in #help
Passing a string property to a command via a button CommandParameter in .NET 6
MainView.xaml
<UserControl x:Class="MeteoApp.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:MeteoApp"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.DataContext>
<local:MainViewModel/>
</UserControl.DataContext>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<GroupBox Grid.Column="0" Header="Search">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" Content="Location"/>
<TextBox Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" Text="{Binding SearchString}"/>
<Button Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Content="Search" Command="{Binding PerformSearch}" CommandParameter="{Binding SearchString, Mode=OneWay}" />

</Grid>
</GroupBox>

<GroupBox Grid.Column="1" Header="Results"/>
</Grid>
</UserControl>
<UserControl x:Class="MeteoApp.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:MeteoApp"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.DataContext>
<local:MainViewModel/>
</UserControl.DataContext>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<GroupBox Grid.Column="0" Header="Search">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" Content="Location"/>
<TextBox Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" Text="{Binding SearchString}"/>
<Button Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Content="Search" Command="{Binding PerformSearch}" CommandParameter="{Binding SearchString, Mode=OneWay}" />

</Grid>
</GroupBox>

<GroupBox Grid.Column="1" Header="Results"/>
</Grid>
</UserControl>
28 replies
CC#
Created by frostfina on 11/2/2022 in #help
Passing a string property to a command via a button CommandParameter in .NET 6
MainModelView.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;

namespace MeteoApp
{
internal class SearchCommand : ICommand
{
public event EventHandler? CanExecuteChanged;

public bool CanExecute(object? parameter)
{
System.Diagnostics.Debug.WriteLine("CanExecute(parameter) : parameter=" + parameter);
return true;
}

public void Execute(object? parameter)
{
System.Diagnostics.Debug.WriteLine("Execute(parameter) : parameter=" + parameter);
}
}

internal class MainViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler? PropertyChanged;

public ICommand? PerformSearch { get; } = new SearchCommand();
private string _searchString = "";
public string SearchString
{
get { return _searchString; }
set
{
_searchString = value;
OnPropertyChanged(SearchString);
}
}

public MainViewModel()
{
}

public void OnPropertyChanged([CallerMemberName] string name = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;

namespace MeteoApp
{
internal class SearchCommand : ICommand
{
public event EventHandler? CanExecuteChanged;

public bool CanExecute(object? parameter)
{
System.Diagnostics.Debug.WriteLine("CanExecute(parameter) : parameter=" + parameter);
return true;
}

public void Execute(object? parameter)
{
System.Diagnostics.Debug.WriteLine("Execute(parameter) : parameter=" + parameter);
}
}

internal class MainViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler? PropertyChanged;

public ICommand? PerformSearch { get; } = new SearchCommand();
private string _searchString = "";
public string SearchString
{
get { return _searchString; }
set
{
_searchString = value;
OnPropertyChanged(SearchString);
}
}

public MainViewModel()
{
}

public void OnPropertyChanged([CallerMemberName] string name = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
}
}
28 replies
CC#
Created by frostfina on 11/2/2022 in #help
Passing a string property to a command via a button CommandParameter in .NET 6
Now however what I don't understand is that it didn't do that before, I must've changed something I thought was irrelevant and now it acts differently ;_;
28 replies
CC#
Created by frostfina on 11/2/2022 in #help
Passing a string property to a command via a button CommandParameter in .NET 6
Same as before, actually I noticed that whatever I set _searchString to first, it just keeps that value for any subsequent call, with or without OneWay
28 replies
CC#
Created by frostfina on 11/2/2022 in #help
Passing a string property to a command via a button CommandParameter in .NET 6
I only change SearchString through a data binding <TextBox [...] Text="{Binding SearchString}"/>
28 replies
CC#
Created by frostfina on 11/2/2022 in #help
Passing a string property to a command via a button CommandParameter in .NET 6
If I programatically set _searchString to some value, it works the first time, but then it doesn't get the new values. I think it gets a reference to the first string instance, then once it changes it becomes null. I guess I can't bind to a property like this since it gets a new instance
28 replies
CC#
Created by frostfina on 11/2/2022 in #help
Passing a string property to a command via a button CommandParameter in .NET 6
But true
28 replies
CC#
Created by frostfina on 11/2/2022 in #help
Passing a string property to a command via a button CommandParameter in .NET 6
I did add an if condition earlier that tested that, and it was null, but I removed it
28 replies
CC#
Created by frostfina on 11/2/2022 in #help
Passing a string property to a command via a button CommandParameter in .NET 6
Yes but if it's set to "" why is it null
28 replies
CC#
Created by frostfina on 11/2/2022 in #help
Passing a string property to a command via a button CommandParameter in .NET 6
But yeah I assumed it was a binding error
28 replies
CC#
Created by frostfina on 11/2/2022 in #help
Passing a string property to a command via a button CommandParameter in .NET 6
I initialized it like this so I doubt it
private string _searchString = "";
public string SearchString
{
get { return _searchString; }
set
{
_searchString = value;
OnPropertyChanged(SearchString);
}
}
private string _searchString = "";
public string SearchString
{
get { return _searchString; }
set
{
_searchString = value;
OnPropertyChanged(SearchString);
}
}
28 replies