15,908,175 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by chawk32 (Top 6 by date)
chawk32
22-Dec-12 18:10pm
View
Hi Christian, So using your suggestion about creating a viewmodel that multiple usercontrols can use I successfully binded one of the usercontrols to two of my properties but the other usercontrol does not bind to one of my properties. Here is some code snippets: First the viewmodel,
public class TournamentModel : INotifyPropertyChanged
{
// Rounds List
private ObservableCollection<rounds> _roundsList = new ObservableCollection<rounds>();
public event PropertyChangedEventHandler PropertyChanged;
private static readonly PropertyChangedEventArgs TextArgs = new PropertyChangedEventArgs("TournamentRounds");
public ObservableCollection<rounds> TournamentRounds
{
get { return _roundsList; }
set
{
_roundsList = value;
NotifyChange(TextArgs);
}
}
private void NotifyChange(PropertyChangedEventArgs e)
{
if (PropertyChanged != null)
{
PropertyChanged(this, e);
}
}
Now the usercontrol (TeamRoundMatchupUserControl.xaml) which is trying to bind to TournamentModel.TournamentRounds.
<combobox itemssource="{Binding TournamentRounds}" displaymemberpath="Name" height="23" horizontalalignment="Center" margin="356,41,416,0" name="roundNameComboBox" verticalalignment="Top" width="178">
The TeamRoundMatchupUserControl.cs class.
private readonly TournamentModel _tournamentModel;
public TeamRoundMatchupUserControl()
{
InitializeComponent();
_tournamentModel = new TournamentModel();
this.DataContext = _tournamentModel;
}
Note: As a test I changed the binding to look at a property called CurrentTournament
which is also in the TournamentModel class and it worked fine. Thoughts?
chawk32
19-Dec-12 16:43pm
View
While I am learning MVVM and data binding in WPF, I am trying to do it the "correct" way so I was purposely avoiding doing things how I knew I could make work and instead try to figure out ways that may end of being more beneficial in the long run. Thanks for your help. It is much appreciated.
chawk32
19-Dec-12 16:35pm
View
See that is the part that I didn't understand. I thought using MVVM that each User Control should have its own View Model. I believe I have read that elsewhere. Can you point to two different View Models from one User Control?
chawk32
19-Dec-12 16:26pm
View
Sorry Christian, I didn't explain myself very well. For the TournamentUserControl I have a class TournamentsViewModel. That is where the collection resides. I would like TeamRoundMatchupUserControl to be bound to that collection. BTW, TeamRoundMatchupUserControl has its own view model.
chawk32
19-Dec-12 16:16pm
View
The issue is I don't know how to bind from one User Control to another so that I can access properties within a User Control.
chawk32
19-Dec-12 16:00pm
View
Christian: I currently have the data in a collection, but the part that I am struggling with is how to bind to that collection which is in one user control and have another user control have access to it.
Show More