Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a grid inside a stack panel.

On the grid I will place several different textboxes that will show positional values that the boxes are databound from my database.

I will want to have buttons to increment/decrement by small, medium, large, etc. amounts.

This is a touchscreen display so I want the user to touch the textbox (or whatever control I should use) and then with it "selected" I want the user to be able to touch one of the several increment/decrement buttons.

The increment/decrement buttons using relay commands need to take the value of the selected textbox(or what control I should use) and then increment/decrement it.

As a note, I will need to be able to know whether and what has changed so I can allow the user to save the changes if they want. I'll need to be able to know what was changed so I can update the database with the new values.

I'm using MVVM with WPF and am stuck as I'm new to WPF.

What I have tried:

Below is my RelayCommand. There are a couple things I've tried and commented out because they didn't work. I did hard code a value of one of the textboxes I created just to make sure, as a start, that I could increment by +5 and it would update properly. This is working. I have no idea how to "pass" that property/value to the RelayCommand.
C#
public RelayCommand cmdIncrementSmall { get; private set; }
public void doIncrementSmall(object? o)
{
    // SelectedAssemblyPosition = item as short;
    //IInputElement focusedElement = FocusManager.GetFocusedElement;
    _LeverHeightLeft += 5;
}

Below is the StackPanel that I've created with the textbox and button as a start to begin testing. Once I have it figured out I can add the other textboxes (or whatever control I should use) and the other increment/decrement buttons.
XAML
<stackpanel x:name="ExercisePositionSetter" margin="1255,3,0,0" height="2017" background="Teal">
<grid>
    <grid.columndefinitions>
        <columndefinition width="160">
        <columndefinition width="160">
        <columndefinition width="160">
        <columndefinition width="160">
        <columndefinition width="160">
        <columndefinition width="160">
        <columndefinition width="160">
        <columndefinition width="160">
        <columndefinition width="160">
        <columndefinition width="160">
        <columndefinition width="160">
        <columndefinition width="160">
        <columndefinition width="160">
        <columndefinition width="*">
    

    <grid.rowdefinitions>
        <rowdefinition height="125">
        <rowdefinition height="125">
        <rowdefinition height="125">
        <rowdefinition height="125">
        <rowdefinition height="125">
        <rowdefinition height="125">
        <rowdefinition height="125">
        <rowdefinition height="125">
        <rowdefinition height="125">
        <rowdefinition height="125">
        <rowdefinition height="125">
        <rowdefinition height="125">
        <rowdefinition height="125">
        <rowdefinition height="125">
        <rowdefinition height="125">
        <rowdefinition height="135">

    
    
    <textblock grid.column="0" grid.row="1" horizontalalignment="Center" verticalalignment="Bottom" fontsize="42" fontweight="SemiBold" textalignment="Center">
        Lever <linebreak>
        Height
    
    <textbox x:name="LeverHeightLeft" grid.column="0" grid.row="2" horizontalalignment="Center" verticalalignment="Bottom" fontsize="42" fontweight="SemiBold" textalignment="Center" 
text="{Binding Path =_LeverHeightLeft}" width="125" isreadonly="True">
Posted
Updated 19-Jul-22 21:39pm
v2

1 solution

It looks like you are at the beginning of learning WPF & MVVM.

I strongly suggest that you do some googling for: wpf tutorials - Google Search[^] & wpf mvvm tutorials - Google Search[^] - there are a number of great free websites and youtubers that will get you up and running very quickly. I'm a seasoned WPF programmer and I still Google when I hit mental blanks. Chances are, someone has found a solution.

But, by far, one of the best YouTubers out there is this guy: WPF Tutorials - SingletonSean, YouTube[^]. He has other playlists on WPF with Entity Framework (database), and much more.

Once you have the basics under control, then if you are stuck, and you hit a dead end with Google researching your issue, Please share a sample of the can(only the bare minimum to reproduce the issue), a description on what you aree trying to achieve, and the specifics of what you are experiencing, including error messages, etc. That way we can help pinpoint or help you in the right direction to resolve your issue.

Hope this helps!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900