|
Hi,
I have a WPF DataGrid made up of DataGridTemplateColumns, that have DatePickers.
I am selecting a particular cell as follows:
var cellToEdit = new DataGridCellInfo(row, column);
this.MyDataGrid.CurrentCell = cellToEdit;
What is happening is that I'm successfully moving to the cell that I want, however the cell in which I was before I moved, is remaining editable and loosing style.
I'm assigning a style in my DatePicker_GotFocus event. I have a handler for this event as follows:
AddHandler(DatePicker.GotFocusEvent, new RoutedEventHandler(DatePicker_GotFocus), true);
I'm noticing that DatePicker_GotFocus is being executed multiple times when moving to the new cell.
Any idea how to solve this issue?
|
|
|
|
|
I have a problem about change the datagrid's header style.
when you clicked the header of datagrid for sort,each time have a arrow icon。I do not want this,how to remove it,the arrow icon。
|
|
|
|
|
There is most certainly a propert of the datagrid that manages the sorting of column. CanSortColumns, or UserCanSort or AllowSort, just take a look through the properties of the datagrid control you are using.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hello forum,
I’ve created a Silverlight application that includes a ADO Entity data model and DomainService class.
In the main page the context is created
MyDomainContext context = new MyDomainContext();
dataGrid1.ItemsSource = dp1;
context.Load(context.GetDBTablesQuery());
The default configuration (in MyDomainServices.cs)works fine.
For example, the following code populates a datagrid.
public IQueryable<dbtable> GetDBTables()
{
return this.ObjectContext.DBTables;
}
My question is: How do I run a simple script
(e.g. Select col1, col2 from DBTable where col1='12')
Many thanks in advance
|
|
|
|
|
I am trying to customize the StringFormat for my datepicker to 'yyyy/MM/dd'. How do I trigger DateValidationError event when the user enters the wrong format. Here's my code:
<Style TargetType="{x:Type DatePickerTextBox}">
<Setter Property="FontSize" Value="16"/>
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<TextBox x:Name="PART_TextBox"
Text="{Binding Path=SelectedDate, StringFormat='yyyy/MM/dd',
RelativeSource={RelativeSource AncestorType={x:Type DatePicker}}}"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Thanks
|
|
|
|
|
I have a WPF C# control that is being used inside a Dynamics AX application. I have set my code in WPF to handle the ENTER key as follows:
private void Datagrid_PreviewKeyDown(object sender, KeyEventArgs e)
{
switch (e.Key)
{
case Key.Enter:
{
// Code here that moves focus to the next cell
e.Handled = true;
break;
}
What is happening, is that when I press the ENTER key the control loses focus and goes out to the next control in AX.
Any way of preventing this, and leaving focus in the grid?
Thanks in advance.
|
|
|
|
|
This is very much a control specific issue, you are going to need to talk to the support forum for the control. It may have a property that will handle the behaviour. I would have thought the preview event should have grabbed the event before the control processes it!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I suggest not to use tunnelling event handling and go for standard bubble handling. Implement OnkeyDown instead and DO NOT set the handled property to true. It breaks WPF's default focus handling mechanism (the one used while pressing the tab key) and sometimes, with certain keys, causes weitrd problems.
|
|
|
|
|
Maybe I wasn't clear. I'm using a standard WPF DataGrid inside a WPF control.
I have now used the User Control (that has the DataGrid in it) PreviewKeyDown Event. and set e.Handled to false, with no luck.
The DataGrid_KeyDown & UserControl_KeyDown are not being executed.
I have even tried to use: System.Windows.Forms.SendKeys.SendWait("{TAB}"); (since I would like my ENTER key to behave as the TAB key)... however my functionality happening when pressing tab, as stated in the event GridView_KeyDown, is not being executed, apart from the focus going to the first cell of my DataGrid.
There is even a boolean property both in the user control and in the datagrid KeyboardNavigation.AcceptsReturn that didn't make any difference when setting true or false.
modified 22-May-13 2:36am.
|
|
|
|
|
I'll try to reproduce your case and say..
|
|
|
|
|
Hi,
I have always used MVVM with all the WPF projects I worked on. Recently I joined a firm where they seem to be using MVVMP pattern (http://www.overroot.com/blog/2011/03/16/how-to-implement-mvvmp-pattern/[^]). Whatever Google search I make around I MVVMP I am ending up at the blog mentioned above. I want to understand does any one else use MVVMP too? If so I want to understand the advantages of MVVMP over MVVM. Any links/references to the topic would be greatly appreciated.
Thanks!
Cheers,
Suresh
|
|
|
|
|
Just something some random dude on the internet made up when he was high. The blog you linked to makes almost no sense. His explanation of why MVVMP is better then MVVM is pretty much "its cooler if you split out your business logic into a separate class from the VM". Well, too bad that's really the models job .
|
|
|
|
|
This pattern may be something they are looking at internally.
Stick to MVVM unless you find tons of material on MVVMP.
|
|
|
|
|
Using the default MVVM light project for Windows Phone, I tried to implement a databinding to a ListBox. Unsuccessfully. The same CS code, placed in the normal code behind seems to bind just fine. But over in the view model, I get nothing but a blank box.
<ListBox x:Name="myListBox" HorizontalAlignment="Left" Height="100"
VerticalAlignment="Top" Width="200">
<ListBox.ItemTemplate>
<DataTemplate>
<ItemsControl ItemsSource="{Binding theList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Width="auto">
<TextBlock Text="{Binding Path=Key}" />
<TextBlock Text="{Binding Path=Value}" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
public Dictionary<string, string> theDictionary;
private List<Dictionary<string, string>> _theList;
public const string theListPropertyName = "theList";
public List<Dictionary<string, string>> theList
{
get
{
return _theList;
}
set
{
if (_theList == value)
return;
_theList = value;
RaisePropertyChanged(theListPropertyName);
}
}
public MainViewModel(IDataService dataService)
{
List<Dictionary<string, string>> x = new List<Dictionary<string, string>>();
theDictionary = new Dictionary<string, string>();
theDictionary.Add("1", "A");
theDictionary.Add("2", "B");
theList = new List<Dictionary<string, string>>();
theList.Add(theDictionary);
}
|
|
|
|
|
Set the items source property of the listbox to your list ("theList") not the items source property of item template.
<ListBox x:Name="myListBox" HorizontalAlignment="Left" Height="100" ItemsSource="{Binding theList}" VerticalAlignment="Top" Width="200">
|
|
|
|
|
Thanks Amitosh, but I think there must be more to it.
I still don't see any data from the ViewModel with an additional ItemsSource={"Binding theList"} on the listbox declaration.
Maybe this is useful: I pulled a reference to the ViewModel in the code behind. I manually assigned myListBox.ItemsSource=vm.theList, and the data appeared!
As to why the one bound through MVVM doesn't work, still a mystery.
modified 19-May-13 21:55pm.
|
|
|
|
|
I agree, I took me a week to understand MVVM architecture, yet not perfectly. I still get weird errors!
Where did you initialize the view model in the code behind or xaml?
Viewmodel should be set as the data context of the root element (window,page,usercontrol... etc).
|
|
|
|
|
|
Ok, I had a look into your code...
You have got the following errors
--In MainViewModel.cs--
Line 42,43 - reference to _welcomeTitle. That should be _theText
Line 47,48 - You have used Dictionary. Binding to a Dictionary doesn't update the view if any value is changed. Get a ObservableDictionary. Unfortunately C# doesn't have such functionality, so google for it.
Line 49,50 - You have used List, Binding to a List doesn't update the view if any value is changed. Use ObservableCollection. It's part of System.Collections.ObjectModel
-----------------------
Now remove all code-behind and see if it works. Also remove the ItemsSource property of the ItemsControl at Line 50. MainPage.xaml
Please consider: Is it necessary to use a dictionary?? It is difficult to bind to a dictionary, you might have possible errors ahead!!
Good Luck!
|
|
|
|
|
Hi,
i have a datagrid implemented in xaml like this:
<DataGrid ItemsSource="{Binding Stuff}" HeadersVisibility="None" GridLinesVisibility="None" AutoGenerateColumns="True" Height="500" Margin="72,363,72,-3" Name="myGrid" VerticalAlignment="Top" Background="{x:Null}" RowBackground="{x:Null}" CanUserAddRows="True" FontSize="20" /><pre lang="xml">
The grid is automatically populated (via a Binding) with two columns and some data. All is well but the text in the columns is left-aligned.
Is it possible to force the text in one of the autogenerated columns to be right-aligned?
Regards
|
|
|
|
|
You should be able to do this by applying a style to the DataGridColumnHeader. Off the top of my head, the following should do it:
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Text="{Binding}" HorizontalAlignment="Right" />
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
|
|
|
|
|
Hi and thanks for the reply.
Unfortunately that did not do the trick. The column headers are hidden so i do not need to right-align them.
Basically the datagrid has two columns of data. I need the DATA in ONE of the columns to be right aligned.
I tried this:
<Style TargetType="DataGrid">
<Setter Property="CellStyle">
<Setter.Value>
<Style TargetType="DataGridCell">
<Setter Property="HorizontalAlignment" Value="Right"/>
</Style>
</Setter.Value>
</Setter>
</Style>
but that just plain righ-aligns everything in the datagrid (data in column 1 and in column 2). Is it possible to apply this to column 2 only?
Note that i do not have the column definitions in my xaml since the datagrid is populated via a binding.
Thanks
|
|
|
|
|
You can use the AutoGeneratingColumn event to handle this. Source[^].
|
|
|
|
|
I have created a SilverLight application that uses ADO and DomainServices to populate a DataGrid from an SQL 2008 database server. The context looks like this
EcDomainContext context1 = new EcDomainContext();
A few months later, I added a table to the database so in order to use this new table, I had to rebuild as follows:
-deleted all MyDomainServices (.cs) files
-deleted the Mymodel (.edmx) file
-recreate by adding the ADO and Domainservices again
-reconfigure the MyDomainServices.cs as before.
Well, I just added another table and I would like to know if there is an easier way to do this?
Many thanks.
Ps
|
|
|
|
|
hi i have made the stickin which i am moving a small box around it using motion path. but when i change the angle of that stick through slider, the box movement "animation" still remains same the original path which i set the default. is there any way i can change its animation by depending on its angle.
|
|
|
|