|
I have 2 answers to your problem:
1. you are doing it wrong! how do you know there is TextBox in your DataGridTemplateColumn? There might not be!
Perhaps you sould provide the binding to the property to filter on as an attached property to your header?
2. if you know there is going to be a some text in the column, you can use the VisualTreeHelper to explore the cell, until you find a TextBlock / TextElement / Run and extract its valueA train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
Super Lloyd
I'd like to thank you for the support.
It was not clear to me how the datatemplate is used at runtime, so finding the textbox in the datatemplate is the wrong way, definitely.
Maybe there is a short cut for me, as I name my columns in a way that I can derive the binding from it ... but I cannot find the name (given using X:Name in Xaml) when I look into the column object during debug. Maybe I am doing something really wrong? So when please enlight me
Regards
Klaus
|
|
|
|
|
Why not use an attached dependency property on your column, such as "Filter.PropertyPath" on your column header?
Other than that the Name property should work, I wonder why it doesn't...A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
Sorry for getting back but as "intermediate beginner in WPF" I think I still have difficulties with the concepts, but:
Regarding the name: I do not see that the class DataGridTemplateColumn (and the normal columns) has a property "Name", so where does "x:Name" go to then and how can I get it at runtime?
Regarding the attached property: The filtering controls are plumbed into the datagridheader using a controltemplate (unfortunately not constructed by me, I followed this article Filtering the WPF DataGrid automatically via the header (inline filtering)[])
Besides the difficulty to construct the binding of the attached property I see the problem that its (the attached propertie's) binding must somehow refer to the binding of the column (which does not exist in the case of the datagridtemplatecolumn), or am I completely wrong
Thanks for your support
Klaus
|
|
|
|
|
x:Name will end up in 2 places.
1 Some WPF classes have a name property (FrameworkElement and Style for exemple) and x:Name will set it.
2. also, in case of a code behind class, the XAML precompiler will generate member with the name in x:Name, provided they are at the top level naming scope (read INameScope documentation) (i.e. not in a template)
ex:
Window1.xaml
<Window
x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Button x:Name="but" Content="Click"/>
</Window>
Window1.xaml.cs
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
but.Click += (o, e) => MessageBox.Show("Button Clicked");
}
}
Other than that a Binding is made of 3 part, a PropertyPath, a source and a target.
The source is generally the DataContext (if not specified) and is different for each row in the grid. And the target is also different in each row (it's the cell) what you want is the PropertyPath, which can easily be set somewhere else.
mm.. reading the article... you are trying to implement UpdateFilter() and need to know the propertyName, are you?
how about you create an attached property in FilteringDataGrid called "FilterPath"?
you can use build in snippet in VS2005/2008, type "propa" followed by TAB, fill the blank!
Then when you declare your columns, set the property:
<dg:DataGridTemplateColumn
FilteringDataGrid.FilterPath="MyProperty"
x:Name="dbcItemName"
Header="{Loc C_ItemName}"
HeaderStyle="{StaticResource styFilterTextBoxColumn}">
<dg:DataGridTemplateColumn.CellTemplate>.....
...... A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
Super Lloyd
yes this works fine ... thanks for your help ...
Regards
Klaus
|
|
|
|
|
Super Lloyd
allow me to come back to you in this issue.
Using the attached property solves the problem of getting the property of the current column, that works fine now.
The reason for using DataGridTemplateColumns have been that I want to have columns in my DataGrid that contain not only a textbox but additional controls (like a button in my case). These are working fine now, but what always was a pain in my app is the lengthy xaml code that is used for the template columns.
Now I started an alternative approach: I derived a new column type from DataGridTextColumn, and I am right now trying to overwrite the GenerateEditingElement event to show a usercontrol (with a textbox and a button in it). This works ok but changes to the textbox text property are not going "back" in my datagrid.
Maybe you have an idea?
I am using this in my datagrid:
<local:DerivedColumn Header="Usercontrol" Binding="{Binding FirstName, Mode=TwoWay}"></local:DerivedColumn>
This is my usercontrol xaml:
<Grid x:Name="grid1" MaxHeight="25">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="25"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="25"/>
</Grid.RowDefinitions>
<TextBox x:Name="txSelect" Text="{Binding UcText, Mode=TwoWay}" />
<Button x:Name="pbSelect" Background="Red" Grid.Column="1" Click="pbSelect_Click">...</Button>
</Grid>
... and the codebehind:
Public Class UcSelect
Private Shared Sub textChangedCallBack(ByVal [property] As DependencyObject, ByVal args As DependencyPropertyChangedEventArgs)
Dim UcSelectBox As UcSelect = DirectCast([property], UcSelect)
End Sub
Public Property UcText() As String
Get
Return GetValue(UcTextProperty)
End Get
Set(ByVal value As String)
SetValue(UcTextProperty, value)
End Set
End Property
Public Shared ReadOnly UcTextProperty As DependencyProperty = _
DependencyProperty.Register("UcText", _
GetType(String), GetType(UcSelect), _
New FrameworkPropertyMetadata(String.Empty, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, New PropertyChangedCallback(AddressOf textChangedCallBack)))
Public Sub New()
InitializeComponent()
grid1.DataContext = Me
End Sub
Private Sub pbSelect_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
'just demo
UcText = UcText + "!"
End Sub
End Class
And now the derived column:
Public Class DerivedColumn
Inherits DataGridTextColumn
Protected Overloads Overrides Function GenerateElement(ByVal oCell As DataGridCell, ByVal oDataItem As Object) As FrameworkElement
Dim oElement = MyBase.GenerateElement(oCell, oDataItem)
Return oElement
End Function
Protected Overloads Overrides Function GenerateEditingElement(ByVal oCell As DataGridCell, ByVal oDataItem As Object) As FrameworkElement
Dim oUc As New UcSelect
Dim oBinding As Binding = CType(Me.Binding, Binding)
oUc.SetBinding(UcSelect.UcTextProperty, oBinding)
Return oUc
End Function
End Class
This shows me the correct data, but changes are ignored (the are rolled back when leaving the grid cell)
Any help would be appreciated
Klaus
|
|
|
|
|
Just an educated guess here, but maybe you can write your user control like that:
.....
<TextBox x:Name="txSelect" Text="{Binding UcText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
.....
TextBox, by default, only update the source on focus lost, and because the UI editing control is removed from the hierarchy probably before the focus lost event, maybe the binding is never triggered....
hence the additional UpdateSourceTrigger in the Binding definition
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
This does not help.
Maybe the problem is not datagrid specific but because it is a itemscontrol? So maybe you know an example where a usercontrol with binding is used in a itemscontrol?
Regards
Klaus
|
|
|
|
|
I just saw something else...
You user control's text...at least on what you wrote, isn't binded to any data!
the TextBox seems to be binded to the UtcText property of the user control...
but do you bind this UtcText property 2 way to your data as well?
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
I do not see your point ... but to some degree I am quite lost with the double bindings in here ... one question: would it be impolite to send you a small project which isolates the problem and where you can take a look "lively" ?
Thanks for your time and effort
Klaus
|
|
|
|
|
hmm.. oke doke...
be aware that I'm rather sick this month and not overtly productive....
my email is "L D buzz at galador word dot net", remove space and buzz word!
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
I'm relatively new to C# and have just started playing around with WPF. As a start I decided to make a simple calculator. I added one of the permade textboxes to take input from the user, but you can't perform addition, subbtraction, and so on, oporations on a string, and it won't let me typecast the string to another type like double. How can I change the textbox input to something I can use, or what is there some other object I can use to get the input?
|
|
|
|
|
You can't cast a string to a number but you can convert it. Any of these will work
string num = "1";
int.Parse(num);
int numOut = 0;
int.TryParse(num, out numOut);
Convert.ToInt32(num); I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Even with each of those lines it still tells me it can't convert from string to int.
in case its signifigant, I'm using Visual Studio 2008 btw.
|
|
|
|
|
You are quite obviously doing something incorrectly, each of those lines is accurate.
Post what you are doing? and please don't forget to format it properly, i.e. use pre tags I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Sorry to take more of your time. I've figured out what I did wrong and have gotten it working now.
|
|
|
|
|
Can you please share code?
|
|
|
|
|
hi..
I am developing a web application and i want to use the silver light tools in my .aspx page so can any one suggest me that how is it possible??
and i am not getting the silver light tools on my tool window i am getting only three tools in silverlight tab that are Pointer,Silverlight,MeadiaPlayer..
so please guide me..
|
|
|
|
|
DX Roster wrote: I am developing a web application and i want to use the silver light tools in my .aspx page so can any one suggest me that how is it possible??
You need to install the Silverlight runtime and the developer SDK.
See here[^]. This should allow you to load Silverlight in an aspx page and also view controls in the Visual Studio tool window.Me, I'm dishonest. And a dishonest man you can always trust to be dishonest. Honestly. It's the honest ones you want to watch out for...
|
|
|
|
|
|
Hi .I can not good speack english !.I use this code in c# :
UserControl1 user = (UserControl1)tabControl1.TabPages[0].Controls[0];
Now i can not write this code equivalent in wpf .
|
|
|
|
|
How do you declare and fill your tab control?
If you use DataTemplate it's going to be rather convoluted and involve guess work and VisualTreeHelper. Absolutely not something you'll do on an everyday basis!A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
Hi,
I want to set the tab order in a windnow which contains ToolBarTray. But it is not setting it. Below is my XAML.
<Window x:Class="WpfApplication2.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<TextBox AcceptsTab="False" Height="23" HorizontalAlignment="Left" Margin="10,10,0,0" Name="textBox2" VerticalAlignment="Top" Width="104" KeyboardNavigation.TabIndex="1"/>
<Label x:Name="lblName" Height="27" HorizontalAlignment="Left" Margin="26,38,0,0" VerticalAlignment="Top" Width="61" Content="_Name" Target="{Binding ElementName=txtName}"></Label>
<TextBox x:Name="txtName" Height="23" Margin="112,38,62,0" VerticalAlignment="Top" KeyboardNavigation.TabIndex="2" />
<ToolBarTray ToolBarTray.IsLocked="True" Margin="4,0,-4,72" Height="55" VerticalAlignment="Bottom">
<ToolBar x:Name="mainToolBar" Background="Transparent">
<Button x:Name="newToolbarButton" KeyboardNavigation.TabIndex="3">
<StackPanel Orientation="Horizontal" Height="16" Width="50" Margin="0" VerticalAlignment="Top" >
<Label Content="New" Margin="4,0,0,0" VerticalAlignment="Center" Height="23" Width="37" />
</StackPanel>
</Button>
<Separator/>
<Button x:Name="helpToolbarButton" Margin="0,-1" KeyboardNavigation.TabIndex="4" >
<StackPanel Orientation="Horizontal">
<Label Content="Help" Margin="4,0,0,0" VerticalAlignment="Center" />
</StackPanel>
</Button>
</ToolBar>
</ToolBarTray>
<Button Height="31" Margin="19.81,0,0,22" Name="button1" VerticalAlignment="Bottom" HorizontalAlignment="Left" Width="77" KeyboardNavigation.TabIndex="5">Button</Button>
<Button Margin="131,0,62,19.75" Name="button2" KeyboardNavigation.TabIndex="6" Height="35.5" VerticalAlignment="Bottom">Button</Button>
</Grid>
</Window>
In the above code I have set the tab order in the order of textBox2,txtName,newToolBarButton,helpToolBarButton,button1,button2.
When I run above code tab order is going in the order of textBox2,txtName,button1,button2,newToolBarButton,helpToolBarButton and then it is not coming out of ToolBarTray.
How to make it working the tab ordering in the order of textBox2,txtName,newToolBarButton,helpToolBarButton,button1,button2.
Please suggest.
|
|
|
|
|
Hi
I have a problem when using a TextBox with TextWrapping=Wrap which is inside a DataTemplate which is inside a ListBox which is inside a StackPanel.
The problem is: when I add new lines to the TextBox, both the ListBox and the StackPanel expand accordingly, but when I remove lines from the TextBox, the ListBox shrinks, but the container StackPanel doesn't shrink (it keeps the same height). That is, the TextBox height causes the DockPanel only to grow.
<StackPanel>
<ListBox>
<ListBox.Resources>
<DataTemplate>
<TextBox AcceptsReturn="True"
TextWrapping="Wrap"
Text="{Binding Path=Text, Mode=TwoWay}"
Text="{Binding Path=SomeProperty, Mode=TwoWay}" />
</DataTemplate>
</ListBox.Resources>
</ListBox>
</StackPanel>
This seems to be a ListBox/DataTemplate problem. Is it a known bug? Does it have a workaround? (please say "yes"...)
Thanks in advance!
|
|
|
|
|
I think it's the ListBox which doesn't shrink, as this sample test told me:
<Window
x:Class="WpfApplication1.Window1"
x:Name="root"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<StackPanel Orientation="Vertical">
<StackPanel>
<ListBox BorderBrush="Black" BorderThickness="1">
<ListBoxItem>
<TextBox
AcceptsReturn="True"
TextWrapping="Wrap"
Text="wqedqw"/>
</ListBoxItem>
</ListBox>
<Button>ok</Button>
</StackPanel>
<Button>2</Button>
</StackPanel>
</Window>
(press enter and delete a few times)
I think you should pay a close look at the Aero ListBox template to understandwhat's going on and how to bend it to your will! A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|