|
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.
|
|
|
|
|
Thanks a lot Pete O'Hanlon.
|
|
|
|
|
Hi,
I'm on the design phase of a WPF desktop application. It has a MainWindow with its WindowState as Maximized and also a Menubar. I want the Mainwindow to display a set of controls when the user selects each menu item, rather than opening another window. Is this possible?
Thanks
|
|
|
|
|
Yes this is possible.
Using the MVP(model view presenter)pattern will achieve this for you.
You best starting point is to do the exercises in Sams-Teach-Yourself-WPF-Hours[^] - i.e read the book and follow the exercises as the book progresses.
Your question hints that you are fairly new to WPF - WPF being something that you cannot generally pick up by playing around with it like winforms I suggest you get started on your reading and good luck
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
It sounds like what you want to do is to have a set of user controls, each of which is loaded depending on a menu option selection.
the Simplest (but probably least efficient depending on memory footprint, number of menu options etc.) is simply to place all of the user controls on teh window, then make them invisible until a menu option is selected.
You could also load the user controls dynamically when a menu option is selected. (see here[^] for one of many examples of how to do that.
MVVM # - I did it My Way
___________________________________________
Man, you're a god. - walterhevedeich 26/05/2011
.\\axxx
(That's an 'M')
|
|
|
|
|
Hi,
Please help me regards this issue, there are more than one textboxes, I have to bind text of all textboxes to a list or observable collection in ViewModel.
|
|
|
|
|
<StackPanel>
<TextBox Text="{Binding MyViewModelList[0]}">
<TextBox Text="{Binding MyViewModelList[1]}">
<TextBox Text="{Binding MyViewModelList[2]}">
</StackPanel>
I'm trying to solve using this code, but is always null.
|
|
|
|
|
Have You set the DataContext to the ViewModel?
David
|
|
|
|
|
Yes David I have set the DataContext. Can you look on above code, is anything missing or else if you have any way then please share with me.
Thanks
|
|
|
|
|
Without knowing what is in your ViewModel, That you have not shown. It would be hard for me to guess.
What you should use is a DataTemplate to display each member of your list.
David
|
|
|
|
|
private List<string> _myViewModelList;
public List<string> MyViewModelList
{
get
{
return _myViewModelList;
}
set
{
if (_myViewModelList != value)
{
_myViewModelList = value;
RaisePropertyChanged("MyViewModelList");
}
}
}
private string MouseDown()
{
string finalString = "";
foreach (string str in MyViewModelList)
{
finalString += str +", ";
}
return finalString;
}
David, can you check it where i am doing mistakes. List has null value when i use mouse down event.
Thanks.
|
|
|
|
|
Where do you set the value of the MyViewModelList ?
The bindings that you showed were reading from the MyViewModelList .
The XAML binding will not create the list for you.
Also to note: adding to, or removing from the MyViewModelList will not cause the RaisePropertyChanged to be raised. As you have this coded, that is raised only when the MyViewModelList property is assigned to (replaced).
|
|
|
|
|
Matt T Heffron can you share any code that will send all textboxes content to the viewmodel list/observablecollection.
Thanks
|
|
|
|
|
First you need to initialize MyViewModelList when the View Model is constructed.
private const int NumberOfStrings = 3;
public ViewModel()
{
MyViewModelList = new List<string>(NumberOfStrings);
for (int i = 0; i < NumberOfStrings; ++i)
{
MyViewModelList[i] = string.Empty;
}
}
public List<string> MyViewModelList { get; private set; }
At this point, the TextBoxes will be bound to the empty strings, and should update the corresponding entry in the MyViewModelList whenever they lose focus.
|
|
|
|
|
Thank you very much Matt T Heffron.
|
|
|
|
|
When I select the row and click on edit button:
-Display one stack panel
-Stack panel has textboxes
-Row items should display in textboxes
|
|
|
|
|
Bind your datagrids ItemsSource to the collection, bind the SelectedItem to an a single instance property of that collection.
Create a container for the text boxes, probably a grid, bind each text boxes text property to the SelectedItem.FieldName
Now go and find some tutorials and work through them because you cannot get enough information from forum posts to learn.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanks Mycroft, it worked...
|
|
|
|