|
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.
|
|
|
|
|
Thanks for the answer, Super Lloyd, but what is the "Aero ListBox template"?
|
|
|
|
|
Download .NET Reflector, download the BAML decompiler add-on.
Then open:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\PresentationFramework.Aero.dllA 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.
|
|
|
|
|
Thanks very much! I'll give it a try.
marcelo.
|
|
|
|
|
Hey folks, I will appreciate if you have used HTML 5, Flash or Silverlight. What can we do in a certain technology that we cannot do in the other. What do you think, which of the three will be popular a year or two out. If down the road we are planing to have both web application and mobile application, which of HTML5, FLash or Silverlight will be best suited. Thanks for your help.
|
|
|
|
|
Mark Walter Smith wrote: HTML5, FLash or Silverlight
Each of these technologies will have their own advantages / disadvantages.
Predicting which one will outlast the other is a very very hard thing to do.
I would suggest you list down what you need to do, and then compare your requirements with what these technologies offer. Choose what gives you what you are looking for.
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...
|
|
|
|
|
|