Mekasu0124
Mekasu0124
Explore posts from servers
CC#
Created by Mekasu0124 on 5/30/2024 in #help
Accessing Function from Nested UI File - Avalonia
Ok so I have the following file structure for my Avalonia MVVM project
root/
|
| - Views/
| | - MenuBar/
| | | - FileMenu.axaml
| | - MainWindowView.axaml
root/
|
| - Views/
| | - MenuBar/
| | | - FileMenu.axaml
| | - MainWindowView.axaml
In my FileMenu.axaml file I have a menu option
<MenuItem Header="_Exit" />
<MenuItem Header="_Exit" />
I know to bind it to a command I would do
<MenuItem Header="_Exit" Command="{Binding Exit}" />
<MenuItem Header="_Exit" Command="{Binding Exit}" />
however, the exit function is in my MainWindowViewModel. So I have two questions. 1. Is it ok if I put the exit command in the FileMenu.axaml.cs file to exit the program? 2. If not, do I create a ViewModel file in the same directory as the FileMenu.axaml file and then call that code behind for all of my nested menu options? either way, if it's ok to stay in the MainWindowViewModel, then how do I properly bind to it? I remember in a Todo tutorial they did something like a this.Something.bind.x or something like that. Let me see if I can find it
17 replies
CC#
Created by Mekasu0124 on 5/20/2024 in #help
✅ How to use a UserControl inside of a Window?
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:MeksIDE.ViewModels"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:uc="clr-namespace:MeksIDE.Views.MenuBar;assembly=MeksIDE"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="MeksIDE.Views.MainWindow"
x:DataType="vm:MainWindowViewModel"
Icon="/Assets/avalonia-logo.ico"
Title="Edimuhtationer">

<Grid RowDefinitions="Auto, *">
<DockPanel Grid.Row="0">
<MenuItem DockPanel.Dock="Top">
<!-- File -->
<uc:FileMenu />
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:MeksIDE.ViewModels"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:uc="clr-namespace:MeksIDE.Views.MenuBar;assembly=MeksIDE"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="MeksIDE.Views.MainWindow"
x:DataType="vm:MainWindowViewModel"
Icon="/Assets/avalonia-logo.ico"
Title="Edimuhtationer">

<Grid RowDefinitions="Auto, *">
<DockPanel Grid.Row="0">
<MenuItem DockPanel.Dock="Top">
<!-- File -->
<uc:FileMenu />
So I've moved part of the menu bar at the top of the screen to another UserControl file as my menu bar has a lot of options so I'm breaking it up. As the code above currently sits, I have a blank screen with an arrow in the top-right corner, but nothing else. I used the reference from this stack overflow comment to put in the xmlns:uc="" and the <uc:FileMenu />. Here is the full code for the <uc:FileMenu /> page that is in Views/MenuBar. I'm just not sure what I'm doing wrong. Thanks
12 replies
CC#
Created by Mekasu0124 on 4/23/2024 in #help
✅ How to work with Python A.I.'s
Ok, although I'm no where near ready to start writing my first line of code, I do want to get an idea of what I'm getting myself into. I'm building the A.I. in python and I'll be building an Avalonia desktop application that will interact with the A.I. What I'm wondering is if there are any libraries, or other, that anyone recommends that would go great with this idea? Thanks.
38 replies
CC#
Created by Mekasu0124 on 4/21/2024 in #help
Visual Studio not placing `{}` on new line
No description
2 replies
CC#
Created by Mekasu0124 on 4/19/2024 in #help
getting some music off Apple Music
Is there a library I can use to pull all of my songs off my Apple Music library and out them on my computer?
13 replies
CC#
Created by Mekasu0124 on 4/18/2024 in #help
✅ Reducing code to separate UserControls for easier readability Avalonia
code: https://pastebin.com/zEFZNhip I'm wanting to learn how to break some of this screen down into a reusable UserControl that I can call in other places as well, but I can't get past creating the /Views/UserControls directory and creating a new user control as I'm not sure what part(s) can be broken down. Thanks
1 replies
CC#
Created by Mekasu0124 on 4/16/2024 in #help
How do I use models from Project A in Project B?
Lets say I have a models folder with a few models in it inside of Project A and I've created another project under the same .sln called Project B. I instead of having to create duplicate models between both projects, I want to use the models with Project A's models folder inside of Project B. I tried
using ProjectA.Models;
using ProjectA.Models;
but I get a resolve error basically saying it can't find it, but the folder structure is
Project/
- ProjectA/
- Models/
- ProjectB/
- Program.cs // use ProjectA.Models here
Project/
- ProjectA/
- Models/
- ProjectB/
- Program.cs // use ProjectA.Models here
. Thanks in advance.
32 replies
CC#
Created by Mekasu0124 on 4/14/2024 in #help
How To Set Vertical Snap Points on Avalonia ScrollViewer
<ScrollViewer Classes="NewUserScroll">
<Grid RowDefinitions="*,*,*,*">
<Border Classes="NewUserBorder" Grid.Row="0"></Border>
<Border Classes="NewUserBorder" Grid.Row="1"></Border>
<Border Classes="NewUserBorder" Grid.Row="2"></Border>
<Border Classes="NewUserBorder" Grid.Row="3"></Border>
</Grid>
</ScrollViewer>
<ScrollViewer Classes="NewUserScroll">
<Grid RowDefinitions="*,*,*,*">
<Border Classes="NewUserBorder" Grid.Row="0"></Border>
<Border Classes="NewUserBorder" Grid.Row="1"></Border>
<Border Classes="NewUserBorder" Grid.Row="2"></Border>
<Border Classes="NewUserBorder" Grid.Row="3"></Border>
</Grid>
</ScrollViewer>
I'm curious to know if this is such a thing. Basically what I'm wanting to do is when the user clicks the buttons to scroll, or uses their mouse wheel, it will either auto scroll or "jump" with a scroll animation to the nth child within each of the borders. Is there a way I can name the border's and achieve this? Thanks.
1 replies
CC#
Created by Mekasu0124 on 4/14/2024 in #help
✅ Auto Completion of AXAML Tags in Rider doesn't work
No description
2 replies
CC#
Created by Mekasu0124 on 4/6/2024 in #help
✅ Index Outside Of Bounds System.Data.SQLite
No description
232 replies
CC#
Created by Mekasu0124 on 4/5/2024 in #help
✅ Change FontSize in ViewModel Avalonia
How would I set the font size in app.axaml under <Application.Resources> so that I can then ask how do I change that font size in the ViewModel? Thanks
2 replies
CC#
Created by Mekasu0124 on 4/4/2024 in #help
✅ Converting From ReactiveUI to Community Toolkit
ok so I'm good on how to use Community Toolkit in the ViewModel, however, I have no idea how it's used for screen navigation in the MainWindowViewModel and I can't find a tutorial online or a youtube video explaining it. Does anyone have anything?
1 replies
CC#
Created by Mekasu0124 on 3/29/2024 in #help
✅ Object reference not set to an instance of an object?
public class UserGenerator
{
private static Random rand = new();

private static List<string> SelectRandomNames(int count)
{
List<string> selectedNames = new();

for (int i = 0; i < count; i++)
{
int index = rand.Next(0, Names.Count);
string name = Names[index];
selectedNames.Add(name);
}

return selectedNames;
}
}
public class UserGenerator
{
private static Random rand = new();

private static List<string> SelectRandomNames(int count)
{
List<string> selectedNames = new();

for (int i = 0; i < count; i++)
{
int index = rand.Next(0, Names.Count);
string name = Names[index];
selectedNames.Add(name);
}

return selectedNames;
}
}
I keep getting a run-time error of Object reference not set to an instance of an object on line int index = rand.Next(0, Names.Count); and I'm not sure why.
9 replies
CC#
Created by Mekasu0124 on 3/25/2024 in #help
✅ Catching different errors using System.Data.SQLite
public void CreateSomeTable()
{
Using SQLiteConnection conn = new(_dbFile);
Using SQLiteCommand cmd = conn.CreateCommand();

conn.Open();

cmd.CommandText = @"CREATE TABLE IF NOT EXISTS
[login] (
[Username] VARCHAR(15),
[Password] VARCHAR(30),
UNIQUE(Username)
)";
try
{
cmd.ExecuteNonQuery();
}
catch (SQLiteException ex)
{
throw new SQLiteExecption ex;
}
}

public void InsertNewUser(UserModel user)
{
Using SQLiteConnection conn = new(_dbFile);
...

cmd.CommandText = @"INSERT INTO login(Username, Password) VALUES ($un, $pw)";
cmd.Parameters.AddWithValue("$un", user.Username);
cmd.Parameters.AddWithValue("$pw", user.Password);

try
{
cmd.ExecuteNonQuery();
}
catch (SQLiteException ex)
{
throw new SQLiteException(ex.Message);
}
}
public void CreateSomeTable()
{
Using SQLiteConnection conn = new(_dbFile);
Using SQLiteCommand cmd = conn.CreateCommand();

conn.Open();

cmd.CommandText = @"CREATE TABLE IF NOT EXISTS
[login] (
[Username] VARCHAR(15),
[Password] VARCHAR(30),
UNIQUE(Username)
)";
try
{
cmd.ExecuteNonQuery();
}
catch (SQLiteException ex)
{
throw new SQLiteExecption ex;
}
}

public void InsertNewUser(UserModel user)
{
Using SQLiteConnection conn = new(_dbFile);
...

cmd.CommandText = @"INSERT INTO login(Username, Password) VALUES ($un, $pw)";
cmd.Parameters.AddWithValue("$un", user.Username);
cmd.Parameters.AddWithValue("$pw", user.Password);

try
{
cmd.ExecuteNonQuery();
}
catch (SQLiteException ex)
{
throw new SQLiteException(ex.Message);
}
}
so I'm wanting to write a custom class that error handles my database. For example:
public class DatabaseErrorHandler()
{
public void HandleUniqueEntryError()
{
// some code here
}
}
public class DatabaseErrorHandler()
{
public void HandleUniqueEntryError()
{
// some code here
}
}
I would somehow (idk how) use the class within the code above for adding a new user to the database. In the create database function, the Username field is unique. A user tries to create a new account with a username that already exists. I would like for the process to be something like 1. user clicks create user button call database function 2. database tries to save -> send error to custom error handler class 3. function for unique errors sends back some type of value to the View for the user to tell them that the username already exists and to try again How would I go about doing this? I wanted to do a custom class so that I could call the error class anywhere I needed throughout my database file and be able to still have the program act accordingly.
30 replies
CC#
Created by Mekasu0124 on 3/23/2024 in #help
✅ How to get value of DatePicker from nested UserControl Avalonia
<!-- in new user view -->
<UserControl xmlns:uc="clr-namespace:MathGame.Views.UserControls;assembly=MathGame">
<Border>
<StackPanel>
<uc:DatePicker />
</StackPanel>
</Border>
</UserControl>

<!-- in ./Views/UserControls/DatePicker.axaml -->
<UserControl>
<DatePicker DayFormat="ddd dd" MonthFormat="MMM MM" />
</UserControl>
<!-- in new user view -->
<UserControl xmlns:uc="clr-namespace:MathGame.Views.UserControls;assembly=MathGame">
<Border>
<StackPanel>
<uc:DatePicker />
</StackPanel>
</Border>
</UserControl>

<!-- in ./Views/UserControls/DatePicker.axaml -->
<UserControl>
<DatePicker DayFormat="ddd dd" MonthFormat="MMM MM" />
</UserControl>
in the CreateNewUserView.axaml file, how do I get access to the date selected within the DatePicker with the DatePicker being in a nested UserControl?
1 replies
CC#
Created by Mekasu0124 on 3/23/2024 in #help
✅ Styling Avalonia DatePicker Control
My Code: https://pastebin.com/v057vZCS Avalonia Code For DatePicker Style: https://pastebin.com/QewxMCD9 I am trying to style this DatePicker, and I'm doing it as it's own UserControl so that I can call it when needed. I want it's style, whether opened or closed, to be with a black background {DynamicResource Background}, specific value hex of blue {DynamicResource BorderColor} for the border and for the spacers in between the day/month/year values whether open or close, and darkgray text {DynamicResource FontColor} whether opened or closed, but I can't figure it out. Any help is appreciated. Thank you.
3 replies
CC#
Created by Mekasu0124 on 3/23/2024 in #help
✅ Allow user to select profile image avalonia
https://docs.avaloniaui.net/docs/concepts/services/storage-provider/file-picker-options I found this on the docs, but I think I'm looking in the wrong place. On the create new user screen in my application, I want to have a part where the user can select a file from their local computer to set as their profile image, however, I'm not having much luck finding any examples, or other users on like Stack Overflow who are trying to do the same thing. Thanks in advance.
16 replies
CC#
Created by Mekasu0124 on 3/17/2024 in #help
✅ How To Get Button To Show Another Screen Avalonia
LoginViewModel: https://pastebin.com/V6dia5A0 MainWindowViewModel: https://pastebin.com/cXSuA4wM I'm trying to get my ForgotPassword and ReturnCreateNewUser buttons to show the screens equivalent to them instead of having to return some value back to the MainWindowViewModel to navigate it. I just can't get it to work. Any ideas are welcome. Thanks in advance
1 replies
CC#
Created by Mekasu0124 on 3/16/2024 in #help
✅ Creating a ToolTip on a TextBox Avalonia
LoginView.axaml: https://pastebin.com/AX548bUA I'm trying to create a ToolTip on the TextBox's on the screen, however, I keep getting
Unable to find suitable setter or adder for property of type Text of type Avalonia.Controls:Avalonia.Controls.TextBox for argument Avalonia.Controls:Avalonia.Controls.ToolTip, available setter parameter list are:
Unable to find suitable setter or adder for property of type Text of type Avalonia.Controls:Avalonia.Controls.TextBox for argument Avalonia.Controls:Avalonia.Controls.ToolTip, available setter parameter list are:
but it doesn't show the list, and it's duplicated twice, once for each TextBox, so what am I doing wrong? Thanks.
2 replies
CC#
Created by Mekasu0124 on 3/16/2024 in #help
✅ make function sleep without freezing ui avalonia
public void LoginScreen()
{
var vm = new LoginViewModel();

Observable.Merge(
vm.Ok,
vm.Cancel
.Select(_ => (UserModel?)null))
.Take(1)
.Subscribe(model =>
{
if (model != null)
{
LoggedInUser.Username = model.Username;
}
else
{
Environment.Exit(0);
}
});

Content = vm;
}
public void LoginScreen()
{
var vm = new LoginViewModel();

Observable.Merge(
vm.Ok,
vm.Cancel
.Select(_ => (UserModel?)null))
.Take(1)
.Subscribe(model =>
{
if (model != null)
{
LoggedInUser.Username = model.Username;
}
else
{
Environment.Exit(0);
}
});

Content = vm;
}
this is my function for the MainWindowViewModel. and this is my ViewModel that matches the LoginViewModel vm https://pastebin.com/uDpQL2cR. 1. My first issue is that in my ReturnUser model, I can't figure out what to return in the if/else if clauses. 2. My second issue is that when i click the Exit button, it's almost immediate. It takes a second or two and then the window closes, but then if I just leave username and password blank and click login, it takes nearly 6 seconds to figure whatever it needs to out and then it displays that the login was successful ... 3. which leads into #3 before #1 became an issue, I did have it to where the else clause was outside of the if statment and not in an else clause so that the code would execute if the check systems didn't fail, however, I think there was a problem with my check system. This is a link to the copy of the code that comes before #1 being an issue https://pastebin.com/jsb8nsqA I'm not really sure what to do. I would like to keep the code I had before #1 became an issue as I was working on cleaning it up and making it better if we could go that route with this code https://pastebin.com/jsb8nsqA MainWindowViewModel.cs (for reference): https://pastebin.com/R8e77kDa
57 replies