logo
down
shadow

Trying to use MVVM to add "ToDoList Task" like item to a StackPanel


Trying to use MVVM to add "ToDoList Task" like item to a StackPanel

Content Index :

Trying to use MVVM to add "ToDoList Task" like item to a StackPanel
Tag : chash , By : user109285
Date : November 27 2020, 05:23 PM

I wish this helpful for you So I'm making a To-Do List app with WPF and I've finished the frontend portion. Now I'm struggling to find a way of actually adding a task that has been entered in the given TextBox. , It seems like you don't set the binding correctly. TextBox should be
 <TextBox x:Name="tasksTextBox" Text="{Binding TaskText}"
  <Button x:Name="addTaskBtn" Command="{Binding NewTaskCommand}"
public void OnPropertyChanged([CallerMemberName]string propertyName = null)
{
    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public string TaskText
    {
        get
        {
            return _taskText;
        }
        set
        {
            if (_taskText != value)
            {
                _taskText = value;
                OnPropertyChanged();
            }
        }
    }
public MainWindow Window
    {
        get;set;
    }

    private MainWindow _Window;
    public void AddNewTask()
    {

        var taskUC = new NewTaskUserControl();

        Window.tasksSP.Children.Add(taskUC);
    }
  public MainWindow()
    {
        InitializeComponent();

        var model=new ViewModel();
        DataContext = model;
        model.Window = this;
    }
<ListBox Margin="0 50 0 0" MaxHeight="300" Grid.Column="2" ItemsSource="{Binding TaskSource}" >
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Grid Margin="0 0 0 0">
                    <Border Background="Orange" CornerRadius="20" Height="80" Width="550">
                        <Grid>
                            <StackPanel Margin="100 0 0 0" VerticalAlignment="Center" TextBlock.FontWeight="DemiBold">

                                <TextBlock Text="{Binding Task}" FontSize="20"/>
                                <TextBlock x:Name="time" FontSize="10"/>
                            </StackPanel>


                            <CheckBox HorizontalAlignment="Left" 
                              Margin="20 0 0 0" 
                              FocusVisualStyle="{x:Null}" 
                              />

                        </Grid>
                    </Border>
                </Grid>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
    public class TaskViewModel : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;
    public void OnPropertyChanged([CallerMemberName]string propertyName = null)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }


    public string Task
    {
        get
        {
            return _Task;
        }
        set
        {
            _Task = value;
            OnPropertyChanged();
        }
    }

    private string _Task;
}
 public ObservableCollection<TaskViewModel> TaskSource
    {
        get
        {
            return _TaskSource;
        }
        set
        {
            _TaskSource = value;
            OnPropertyChanged();
        }
    }

    private ObservableCollection<TaskViewModel> _TaskSource=new ObservableCollection<TaskViewModel>();


    public void AddNewTask()
    {
        TaskSource.Add(new TaskViewModel() { Task = Task });

        //var taskUC = new NewTaskUserControl();
        //Window.tasksSP.Children.Add(taskUC);
    }

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Silverlight MVVM: how to avoid polluting my model while still implementing "add new item" for my datagrid?


Tag : silverlight , By : Yst
Date : March 29 2020, 07:55 AM
it should still fix some issue I have a DataGrid. Right now it's binding to an ObservableCollection in my model just great. ,
That stuff definitely doesn't belong in my model.

Going through Apple's ToDoList app tutorial, item tapping doesn't add "completed" checkmark properly.


Tag : ios , By : Dov
Date : March 29 2020, 07:55 AM
I wish this help you When I tap an item, it doesn't seem to register and add a checkmark on the right. When I tap a subsequent item, it shows a checkmark next to the one I tapped previously, but not for the one I just tapped, and so on, always remaining one action behind.
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

React: how change "const Todo = ({todo, todoList, remove}) => {" to "export default class Todo extends


Tag : reactjs , By : KingGuppy
Date : March 29 2020, 07:55 AM
I wish did fix the issue. The 1st is a stateless component, or a function component, that is passed the props and context as params. The 2nd is a class component, and the props are assigned to this.props. See Components and Props in the documentation.
The props are not passed to render() as params. Destructure this.props to your variables.
render() {
    const {todo, todoList, remove} = this.props;
    const status = todo.opened ? 'opened' : 'closed';

    return (
        <li className={"todo " + status} data-endpoint={todo['@id']}>
            <form onChange={this.changeStatus}>
                <a href={window.Routing.generate('todo_list_todo_show', {account: todoList.account.id, list: todoList.id, todo: todo.id}, true)}>{todo.name}</a>
            </form>
        </li>
    );
}

Following MVVM pattern, how to create a "Settings" function that sets the data-bound item values in other user


Tag : chash , By : nobodyzzz
Date : March 29 2020, 07:55 AM
This might help you I'll give you my idea according to what I understood from your question.
MainWindow.xaml.cs
    public partial class MainWindow : Window
{
    private AppleViewModel appleViewModel;
    public AppleViewModel AppleViewModel
    {
        get
        {
            return this.appleViewModel;
        }
        set
        {
            if (this.appleViewModel != value)
            {
                this.appleViewModel = value;
            }
        }
    }

    private BananaViewModel bananaViewModel;
    public BananaViewModel BananaViewModel
    {
        get
        {
            return this.bananaViewModel;
        }
        set
        {
            if (this.bananaViewModel != value)
            {
                this.bananaViewModel = value;
            }
        }
    }


    public MainWindow()
    {
        InitializeComponent();

        this.AppleViewModel = new AppleViewModel();
        this.AppleViewModel.AppleID = "Apple001";
        this.AppleViewModel.Size = 10;

        this.BananaViewModel = new BananaViewModel();
        this.BananaViewModel.BananaID = "Banana001";
        this.BananaViewModel.Length = 10;

        apple.DataContext = this.AppleViewModel;

        banana.DataContext = this.BananaViewModel;

        ObservableCollection<int> sizes = new ObservableCollection<int>();
        for (int i = 0; i < 10; i++)
        {
            sizes.Add(i);
        }

        ListBox.ItemsSource = sizes;

    }

    private void ListBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if (this.AppleViewModel.IsSelected)
        {
            this.AppleViewModel.Size = (int)ListBox.SelectedItem;
        }
        if (this.BananaViewModel.IsSelected)
        {
            this.BananaViewModel.Length = (int)ListBox.SelectedItem;
        }
    }
}
 <StackPanel Orientation="Vertical">
        <wpfApplication4:AppleControlxaml x:Name="apple"/>
        <wpfApplication4:BananaControl x:Name="banana"/>
        <ListBox SelectionChanged="ListBox_OnSelectionChanged" x:Name="ListBox">
        </ListBox>
    </StackPanel>
private bool isSelected;
    public bool IsSelected
    {
        get
        {
            return this.isSelected;

        }
        set
        {
            this.isSelected = value;
            OnPropertyChanged("IsSelected");
        }
    }
<CheckBox IsChecked="{Binding IsSelected}"/>
private void InitializeSettingsVM(int value, string description)
    {
      //Same like you do when you initialize your Banana/AppleVM in your MainWindow initialize.
      this.SettingsVM.Value = value;
      this.SettingsVM.Description = description;
    }
private void banana1_MouseDown(whateveryouhavehere)
   {
     //Whatever you do here
     this.InitializeSettingsVM(this.BananaViewModel.Length,this.BananaViewModel.BananaID);
   }

MVVM Light templates not showing in "Add Item" menu (VS 2017)?


Tag : wpf , By : Murali Ravipudi
Date : March 29 2020, 07:55 AM
wish help you to fix your issue MVVM Light NuGet can only add related resources (assemblies/.cs files) into the project. It wont add Templates into Visual Studio. To get templates in Visual Studio, you have to install MVVM Light Visual Studio Extension by following the below steps.
Open Visual Studio and go to Tools->Extensions and Updates. In the Extensions and Updates window lick Online in the left pane. In the search bar, type MVVM Light. In the search results find MVVM Light for VS2017. Click Download and accept license.
Related Posts Related QUESTIONS :
  • C# XDocument Element/Elements returns null
  • Autofac keyed service with IEnumerable relationship type
  • Installing EntityFramework via NuGet manager
  • Always Check if there is Internet Connection Xamarin forms
  • WCF OneWay service slows down when aspNetCompatibilityEnabled is set to false
  • Can we use JsonRequestBehavior.AllowGet with [HttpPost] attribute?
  • How to customize the Setup wizard with custom forms in Visual Studio setup project
  • C# ASP.NET - Use method from another class to create labels
  • C# List IList or IEnumerable as argument
  • Parsing File with C# And Replace method
  • Losing special unicode characters in encryption (C#)
  • Getting stored procedure returned value instead of row affected
  • How can I construct HTML using NameValuePair in android?
  • Loading a pop up page in ASP.net through a js file
  • How to pass alert or notification message from controller to View?
  • C# to pause, turn on ssas server, backup cube.... how to?
  • How to execute DataTable.Select() for a column of custom class type for a particular element in that C#
  • how to connect mysql8.0 with C#
  • Passing incorrect values into MultiValueConverter by MultiBinding
  • Can i use IEnumerator as Update func?
  • How to convert API Json response to C# Array?
  • Blazor Textfield Oninput User Typing Delay
  • Performing both layout and render transform results in wrong output
  • uwp beforetextchanged cursor moving in front of text
  • How to keep duplicates from a string[] exclude words from a List and print them out
  • .Net Core Strings.Asc/Mid/Chr/Len missing even after importing Microsoft.VisualBasic
  • How to return to previous search page without being asked to Confirm Form Re-submission and keeping the results on ASP.N
  • How set a identity scaffolding item/page how initial page in asp.net MVC core?
  • LINQ isn't calling Dispose on my IEnumerator when using Union and Select, expected behavior or bug?
  • What is "ByteArray.uncompress()" in AS3 equivalent to in C#?
  • Getting a specific letter from a string variable for my simple guessing game for clues
  • Send an email with Outlook without a subject --- dialog box issue
  • passing List<MyModel> from my controller in the "WebInterfaceProject" to the processor method in "D
  • How to convert Word document created from template by OpenXML into MemoryStream?
  • How can I make a single slider that changes the color of an object?
  • Remap JSON parameter in c#
  • What is the difference between "this ref" and "ref this" when talking about C# 7.2 ref extension met
  • Convert OpenSSL encryption into native C#
  • Accessing Properties in Razor Pages
  • How to get SOAP element value
  • Projection after Group
  • C# error cannot convert sytem.text.regularexpressions.match to string
  • Issues with Save/Load System in a Text Based Adventure game made with ScriptableObjects in Unity
  • VS2019 MSBuild.exe - ASP .Net MVC project fails to publish when using PublishProfile, but works when using OutDir parame
  • Does <pages validateRequest="false" /> in Web.config still matter?
  • How to send new request to redirect URL with new access token
  • Attempt to invoke virtual method on a null object reference Xamarin LockScreen
  • "The attribute names could not be inferred from bind attribute 'bind-value'" exception in Blazor
  • How to fix ''System.ArgumentException" in c#?
  • C#. Ref returning delegate for ref extension method
  • Swashbuckle Swagger generate an actual guid
  • Trying to make thousands of database calls simultaneously - they stack instead of running concurently
  • run mstest from cmd using testcontainer
  • How to make M:N (many-to-many) relationship where both M and N are the same entities?
  • Consume COM DLL from multiple clients
  • Convert json string response representing UCHAR array to Byte array
  • Why does this LinqPad program produce different results on the second run?
  • ServiceStack how to use MaxLoginAttempts feature
  • What does "late-bound access to the destination object" mean?
  • How to load appsettings.json inside a Static class based on deploy environment so that I can use in other class librarie
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com