|
![Go to Parent](https://www.codeproject.com/App_Themes/CodeProject/Img/arrow-up24.png) yes, the add method is on different page (UserViewModel). this is the code :
void Register()
{
Crypto Crypt = new Crypto(Crypto.CryptoTypes.encTypeTripleDES);
Password = Crypt.Encrypt(Password);
CreatedBy = "builtinapp";
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings[
"dLondre.Properties.Settings.CSLONDRE"].ConnectionString);
string str = "";
str = "";
str += "INSERT INTO [user] ";
str += "(firstName,lastName,gender,birthdate,address,city,zip,email,userid,password,status,deleted,createdOn,createdBy) ";
str += "VALUES (@FirstName,@LastName,@Gender,@BirthDate,@Address,@City,@ZipCode,";
str += "@Email,@UserId,@Password,@Status,@Deleted,@CreatedOn,@CreatedBy)";
SqlCommand com = con.CreateCommand();
com.CommandText = str;
com.Parameters.Add(new SqlParameter("@FirstName", FirstName));
com.Parameters.Add(new SqlParameter("@LastName", LastName));
com.Parameters.Add(new SqlParameter("@Gender", Gender));
com.Parameters.Add(new SqlParameter("@BirthDate", BirthDate));
com.Parameters.Add(new SqlParameter("@Address", Address));
com.Parameters.Add(new SqlParameter("@City", City));
com.Parameters.Add(new SqlParameter("@ZipCode", ZipCode));
com.Parameters.Add(new SqlParameter("@Email", Email));
com.Parameters.Add(new SqlParameter("@UserId", UserID));
com.Parameters.Add(new SqlParameter("@Password", Password));
com.Parameters.Add(new SqlParameter("@Status", Status));
com.Parameters.Add(new SqlParameter("@Deleted", Deleted));
com.Parameters.Add(new SqlParameter("@CreatedOn", CreatedOn));
com.Parameters.Add(new SqlParameter("@CreatedBy", CreatedBy));
con.Open();
int rownum = com.ExecuteNonQuery();
com.Dispose();
con.Close();
con.Dispose();
Reset();
}
how to add new user to same exact observablecollection ?
please help. I'm stuck for almost 2 weeks ![Frown | :(](https://www.codeproject.com/script/Forums/Images/smiley_frown.gif)
|
|
|
|
|
Yeah, so this code is just inserting it into the database. There is no notification to the other page to add/refresh the ObservableCollection.
What exactly do you mean by "page"? There is no such thing in WPF. Page is more web/silverlight. Do you mean a dialog?
How do you launch the add dialog? In your command handler for that, you'd show the dialog, then refresh the ObservableCollection afterwards.
|
|
|
|
|
|
SledgeHammer01 wrote: What exactly do you mean by "page"? There is no such thing in WPF. Yes there is. WPF does support Page, wee here[^].
|
|
|
|
|
Finally I Found the solution
maybe it's just trick but it works..
I Just follow article in this link
http://blog.cylewitruk.com/2010/10/mvvm-using-a-timer-in-your-viewmodel/[^]
Here is the code :
private ShowUser showuser;
private void InvalidateSampleData(object state, EventArgs e)
{
showuser = new ShowUser();
Users = showuser.GetUser();
}
public class ShowUser : INotifyPropertyChanged
{
public ObservableCollection<User> GetUser()
{
ObservableCollection<User> users = new ObservableCollection<User>();
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings[
"dLondre.Properties.Settings.CSLONDRE"].ConnectionString);
string str = "";
str += "SELECT userid,firstname + ' ' + lastname as name FROM [user] ";
SqlCommand com = con.CreateCommand();
com.CommandText = str;
try
{
con.Open();
SqlDataReader sdr = com.ExecuteReader();
while (sdr.Read())
{
users.Add(new User { UserID = (string)sdr["userid"], FirstName = (string)sdr["name"] });
}
com.Dispose();
con.Close();
con.Dispose();
}
catch (Exception e)
{
Console.WriteLine(e);
}
return users;
}
#region Methods
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
#endregion
}
private ObservableCollection<User> _users;
public ObservableCollection<User> Users
{
get { return _users; }
set
{
if (value != _users)
_users = value;
OnPropertyChanged("Users");
}
}
User _user;
public User SelectedUserID
{
get { return _user; }
set
{
_user = value;
OnPropertyChanged("SelectedUserID");
}
}
Thanks for any help and suggestion to this thread
I really appreciate it..
now I can die in peace.. ![Wink | ;)](https://www.codeproject.com/script/Forums/Images/smiley_wink.gif)
|
|
|
|
|
private void LoadDataVoidOnPageWichContainsYourComboBoxItemSource()
{
ComboUserData.CollectionChanged += ComboUserData_CollectionChanged;
}
void ComboUserData_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
OnPropertyChanged("ComboUserData");
}
|
|
|
|
|
I'm going to deploy my WPF using ClickOnce. I want to have the users deploy from my server. But what do I need to do on my server to prepare? Do I need to set up a web site? I Googled on this but didn't find much.
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
|
You didn't understand my question
Do I need to do something on my server? Do I need to set up a site in IIS? What URL/IP do my users get?
If it's not broken, fix it until it is
|
|
|
|
|
No you need nothing in IIS unless you are hosting a website itself.
|
|
|
|
|
Hi Kevin. There are 2 alternatives to deploy a WPF application with click once. Create a shared folder on your server, where everyone who needs to install the application has access to. The in your application properties, under publish, you just set the Publishing Folder Location to point to this folder, and leave Installation Folder URL blank. Once you publish it, a setup file will be available for users to install it on their machine.
The second way I do it in IIS, is to create an FTP site, and a standard website. I then use the ftp site as the Publishing Folder Location, and the standard web site as the Installation Folder URL. I then publish it via ftp, and the users can browse to the web site url and install it from there. When you create the web site, you do not need to create any pages or anything, Visual Studio does all this for you when you publish.
Hope this helps
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
My TreeView:
<controls:TreeViewEx BorderThickness="0"
Margin="5"
ItemsSource="{Binding Nodes}"
IsManipulationEnabled ="True"
Visibility="{Binding ShowTree, Converter={StaticResource visibilityConverter}}">
<controls:TreeViewEx.Resources>
<SolidColorBrush Color="Transparent" x:Key="{x:Static SystemColors.HighlightBrushKey}"/>
</controls:TreeViewEx.Resources>
</controls:TreeViewEx>
and the HierarchicalDataTemplate:
<HierarchicalDataTemplate DataType="{x:Type models:JobSummaryModel}"
ItemsSource="{Binding Path=Nodes}">
<Grid Margin="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<controls:TextBlockEx Grid.Column="1"
FontSize="12">
<Hyperlink Style="{StaticResource linkStyle}"
Command="{Binding SelectedNodeCommand}">
<TextBlock Text="{Binding Caption}"/>
</Hyperlink>
</controls:TextBlockEx>
</Grid>
</HierarchicalDataTemplate>
I'm getting a binding error in the outout window. The SelectedNodeCommand is on the ViewModel. How do I bind the hyperlink to it?
Thank you
If it's not broken, fix it until it is
|
|
|
|
|
You can't bind to the VM from a standalone DataTemplate as there is no DataContext there.
|
|
|
|
|
Ok, so what's the way to handle the user clicking the link?
If it's not broken, fix it until it is
|
|
|
|
|
One way to do it is to bind back up the data template hierarchy using FindAncestor to hook into the DataContext there. It's a bit of a hack though.
|
|
|
|
|
I was going to say this... the other option is to inline the HierarchialDataTemplate into the control XAML itself rather then putting it in the resource section as a standalone template.
|
|
|
|
|
Could you show me how this is done?
Thank you
[EDIT]
I thought this would do it. I compiles & runs with no binding errors, but nothing happens when I click a link:
<Hyperlink NavigateUri="{Binding Caption}"
Foreground="#0C2DAA"
Style="{StaticResource linkStyle}"
CommandParameter="{Binding}"
Command="{Binding Path=DataContext.SelectedNodeCommand,
RelativeSource={RelativeSource FindAncestor,
AncestorType={ x:Type views:JobListView}}}">
<InlineUIContainer>
<TextBlock Text="{Binding Caption}" />
</InlineUIContainer>
</Hyperlink
>
If it's not broken, fix it until it is
|
|
|
|
|
Correct syntax is something like:
{Binding Path=ActualWidth, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=GridViewColumnHeader}}
{RelativeSource Mode=FindAncestor, AncestorType=ctrls:ListViewEx}
All the ones I have just say AncestorType=whatever:whatever, none use {}'s and x:Type... you can try that... the other option is inlining:
<TreeView>
<TreeView.ItemTemplate>
<HierarchicalDataTemplate>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
|
|
|
|
|
This works, although I don't pretend to completely understand it
<HierarchicalDataTemplate DataType="{x:Type models:JobSummaryModel}"
ItemsSource="{Binding Path=Nodes}">
<Grid Margin="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Image Source="/FMG.UI.WPF.Shared;component/Media/Images/job_72.png"
Grid.Column="0"
Height="16"
Width="16"
Margin="0,0,3,0"/>
<TextBlock Grid.Column="1">
<Hyperlink NavigateUri="{Binding Caption}"
Foreground="#0C2DAA"
Style="{StaticResource linkStyle}"
CommandParameter="{Binding}"
Command="{Binding Path=DataContext.SelectedNodeCommand,
RelativeSource={RelativeSource FindAncestor,
AncestorType={ x:Type views:JobListView}}}">
<InlineUIContainer>
<TextBlock Text="{Binding Caption}"
FontSize="12"/>
</InlineUIContainer>
</Hyperlink>
</TextBlock>
</Grid>
</HierarchicalDataTemplate>
If it's not broken, fix it until it is
|
|
|
|
|
I want to create dynamically textbox and also bind the contents of these textbox to view model. Suppose I want to create more than one textbox depending on user input(number of textboxes).
Please help me regards this, I am new to MVVM pattern.
modified 7-Nov-13 5:49am.
|
|
|
|
|
1 texbox - create the textbox inxaml and bind the visibility property to the VM
Multiple textboxes - use a collection control (listbox) and bind the ItemsSource to a collection in the VM.
You need to learn the functionality of the controls you have available to you.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanks Mycroft Holmes....
Creation of one textbox is working, but I have to create multiple textbox. I am new to MVVM, please post one sample code to create multiple textbox.
|
|
|
|
|
Please stop. This is not the way to learn MVVM. Right now, you are tackling MVVM in a very haphazard fashion and getting your information through answers on a forum is not the right way to learn the basics. There are many excellent resources available to learn MVVM from, I suggest that you pause and actually use these resources. You can even get free training inside Visual Studio[^].
|
|
|
|
|
I am new to MVVM, facing problems so I am asking my problem. And whatever you gave the way to learn that is also not for beginner, its a complex way.
|
|
|
|
|
Utter rubbish. The training is designed for complete beginners. You are wasting your time and ours by trying to learn this way. If you actually took the time to do the training, you would learn much quicker and much more effectively.
|
|
|
|