|
koleraba wrote: But all Properties of the UserCredentialsHeaderContent are null.
I don't see any place you're calling the deserialization code.
Am I missing something?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
No you are not missing it. When I was implementing the custrom header class, I was looking which metod to overrite to deserialize the header, but I did not find anything. I know that serialization should be done in the OnWriteHeaderContent but there is no OnReadHeaderContent. Do you know where the deserialization code should be. Thank you for your reply.
Uros
|
|
|
|
|
koleraba wrote: Do you know where the deserialization code should be.
A ReadHeader method is in your class, but you need to call it.
I modified the parameter type of your code like this:
public static UserCredentialsHeaderContent ReadHeader(MessageHeaders headers)
{
int headerIndex = headers.FindHeader(HEADER_NAME, HEADER_NAMESPACE);
if (headerIndex != -1)
{
XmlNode[] contentNode = headers.GetHeader<XmlNode[]>(headerIndex);
string text = contentNode[0].InnerText;
XmlSerializer deSerializer = new XmlSerializer(typeof(UserCredentialsHeaderContent));
StringReader stringReader = new StringReader(text);
UserCredentialsHeaderContent content = (UserCredentialsHeaderContent)deSerializer.Deserialize(stringReader);
stringReader.Close();
return content;
}
else
{
return null;
}
}
and called it like this
UserCredentialsHeaderContent headercontent = UserCredentialsMessageHeader.ReadHeader(OperationContext.Current.IncomingMessageHeaders);
Works fine.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark thank you for your time. In the mean time I found the same solution and it works fine. But as you said you have to call the deserialization code by your self - there isn't any method that you could override.
Thanks again for your time
Uroš
|
|
|
|
|
How does one override the default listview item background:
clear - for unselected items
blue - for selected items when the listview has keyboard focus
silver - for seleected items when the listview does not have keyboard focus?
|
|
|
|
|
Try using Google: I use the site tage so it only searches microsoft:
'listview WPF C# .NET site:microsoft.com'
You have to make a template for it....
<Style x:Key="{x:Type ListView}" TargetType="ListView">
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListView">
<Border Name="Border"
BorderThickness="1"
BorderBrush="{StaticResource SolidBorderBrush}"
Background="{StaticResource WindowBackgroundBrush}">
<ScrollViewer Style="{DynamicResource
{x:Static GridView.GridViewScrollViewerStyleKey}}">
<ItemsPresenter />
</ScrollViewer>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsGrouping"
Value="true">
<Setter Property="ScrollViewer.CanContentScroll"
Value="false"/>
</Trigger>
<Trigger Property="IsEnabled"
Value="false">
<Setter TargetName="Border"
Property="Background"
Value="{StaticResource DisabledBorderBrush}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
~TheArch
|
|
|
|
|
Is there any way to know the user clicked the DataGrid column to change the sorting?
|
|
|
|
|
I never worked with DataGrid but I would take a look at the SortCommand event of the DataGrid.
Greetings
Covean
|
|
|
|
|
I am using Silverlight 3, and there is no SortCommand event with DataGrid. Thanks for your reply.
|
|
|
|
|
Sorry my fault, I didn't mentioned that I answered to a silverlight question.
Sorry for that.
Greetings
Covean
|
|
|
|
|
Guys,
I'm trying a simple animation in code behind with a start/stop button.
However, my animation does not want to stop for some reason (despite MSDN showing me the same as I did).
It's probably something small I did wrong, but I can't find it.
I'm also a litte puzzled with the PropertyPath object.
Many thanks.
private void btn_start_Click(object sender, RoutedEventArgs e)
{
if(sb == null){
sb = new Storyboard();
da = new DoubleAnimation();
da.From = 0;
da.To = 360;
da.Duration = new Duration(new TimeSpan(0, 0, 10));
da.RepeatBehavior = RepeatBehavior.Forever;
rectangle_animation.RenderTransform = new RotateTransform();
rectangle_animation.RenderTransformOrigin = new Point(0.5, 0.5);
rectangle_animation.RenderTransform.BeginAnimation(RotateTransform.AngleProperty, da);
sb.Children.Add(da);
Storyboard.SetTargetProperty(da, new PropertyPath("Background.Opacity"));
sb.Begin(this, true);
}
else{
sb.Resume(this);
}
btn_stop.Visibility = Visibility.Visible;
btn_start.Visibility = Visibility.Hidden;
}
private void btn_stop_Click(object sender, RoutedEventArgs e)
{
if(sb != null){
sb.Pause(this);
}
btn_stop.Visibility = Visibility.Hidden;
btn_start.Visibility = Visibility.Visible;
}
|
|
|
|
|
I think it is that you are using the pause method look at this from MSDN:
This method pauses the storyboard, but has no discernible effect if it
is not active or currently paused. As a side effect, all associated
children are also paused.
A controllable storyboard can pause, resume, seek, stop, and be removed. To
make a storyboard controllable in code, you must use the appropriate
overload of the storyboard's Begin method and specify true to make it
controllable. For an example, see How to: Control a Storyboard After It
Starts.
Try using the stop method instead.
|
|
|
|
|
thanks, in meantime I was able to add a second animation (color).
I probably set the PropertyPath wrong.
I used Background.color as propertypath for the color animation, which puts the window background in color, animates it AND pauses correctly (while the rotation continues).
My goal is however to rotate and change color of the rectangle only. I feel I'm near, but the PropertyPath is still illuding me a little.
(for the record, one of the errors was indeed that you have to use the overloaded Begin method with Controllable set to True.)
|
|
|
|
|
FYI, I got it to work. Here's the code.
The result is that only the Rectangle will turn and change color when starting the animation. They both stop when stopping the animation.
if(sb == null){
sb = new Storyboard();
da = new DoubleAnimation();
da.From = 0;
da.To = 360;
da.Duration = new Duration(new TimeSpan(0, 0, 10));
da.RepeatBehavior = RepeatBehavior.Forever;
rectangle_animation.RenderTransform = new RotateTransform();
rectangle_animation.RenderTransformOrigin = new Point(0.5, 0.5);
ca = new ColorAnimation();
ca.From = Colors.Red;
ca.To = Colors.Blue;
ca.Duration = new Duration(new TimeSpan(0, 0, 10));
ca.RepeatBehavior = RepeatBehavior.Forever;
ca.AutoReverse = true;
if(rectangle_animation.Fill == null){
rectangle_animation.Fill = new SolidColorBrush();
}
this.RegisterName("rectangle_angle", rectangle_animation.RenderTransform);
Storyboard.SetTargetName(da, "rectangle_angle");
Storyboard.SetTargetProperty(da, new PropertyPath(RotateTransform.AngleProperty));
this.RegisterName("rectangle_brush", (SolidColorBrush)rectangle_animation.Fill);
Storyboard.SetTargetName(ca, "rectangle_brush");
Storyboard.SetTargetProperty(ca, new PropertyPath(SolidColorBrush.ColorProperty));
sb.Children.Add(da);
sb.Children.Add(ca);
sb.Begin(this, true);
}
else{
sb.Resume(this);
}
btn_stop.Visibility = Visibility.Visible;
btn_start.Visibility = Visibility.Hidden;
}
private void btn_stop_Click(object sender, RoutedEventArgs e)
{
if(sb != null){
sb.Pause(this);
}
btn_stop.Visibility = Visibility.Hidden;
btn_start.Visibility = Visibility.Visible;
}
|
|
|
|
|
Hey could you comment the code or put some highlights in so theirs can easily identify what your solution was?
Also if you use the pre tag make sure that the code fits on the page, if you see a scroll bar at the bottom you will need to adjust the formatting.
I would like to know what you had to do....
Good to see you got it working....
|
|
|
|
|
Reformat? No way, that would come out more ugly, but here's the code with additional comments.
Note I continued playing with it.
private void btn_start_Click(object sender, RoutedEventArgs e)
{
if(sb == null){
sb = new Storyboard();
da = new DoubleAnimation();
da.From = Convert.ToInt32(txtbox_anglefrom.Text);
da.To = Convert.ToInt32(txtbox_angleto.Text);
string [] timespan = txtbox_duration.Text.Split(new string [] {":"}, StringSplitOptions.None);
da.Duration = new Duration(new TimeSpan(Convert.ToInt32(timespan[0]), Convert.ToInt32(timespan[1]), Convert.ToInt32(timespan[2])));
da.RepeatBehavior = RepeatBehavior.Forever;
da.AutoReverse = true;
rectangle_animation.RenderTransform = new RotateTransform();
rectangle_animation.RenderTransformOrigin = new Point(0.5, 0.5);
ca = new ColorAnimation();
ca.From = Colors.Red;
ca.To = Colors.Blue;
ca.Duration = new Duration(new TimeSpan(Convert.ToInt32(timespan[0]), Convert.ToInt32(timespan[1]), Convert.ToInt32(timespan[2])));
ca.RepeatBehavior = RepeatBehavior.Forever;
ca.AutoReverse = true;
if(rectangle_animation.Fill == null){
rectangle_animation.Fill = new SolidColorBrush();
}
this.RegisterName("rectangle_angle", rectangle_animation.RenderTransform);
Storyboard.SetTargetName(da, "rectangle_angle");
Storyboard.SetTargetProperty(da, new PropertyPath(RotateTransform.AngleProperty));
this.RegisterName("rectangle_brush", (SolidColorBrush)rectangle_animation.Fill);
Storyboard.SetTargetName(ca, "rectangle_brush");
Storyboard.SetTargetProperty(ca, new PropertyPath(SolidColorBrush.ColorProperty));
sb.Children.Add(da);
sb.Children.Add(ca);
sb.Begin(this, true);
txtbox_duration.IsEnabled = false;
txtbox_anglefrom.IsEnabled = false;
txtbox_angleto.IsEnabled = false;
}
else{
sb.Resume(this);
}
btn_stop.IsEnabled = true;
btn_start.IsEnabled = false;
}
private void btn_stop_Click(object sender, RoutedEventArgs e)
{
if(sb != null){
sb.Pause(this);
}
btn_stop.IsEnabled = false;
btn_start.IsEnabled = true;
}
private void btn_close_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void btn_restart_Click(object sender, RoutedEventArgs e) {
sb.Stop(this);
sb = null;
this.UnregisterName("rectangle_angle");
this.UnregisterName("rectangle_brush");
btn_stop.IsEnabled = false;
btn_start.IsEnabled = true;
txtbox_duration.IsEnabled = true;
txtbox_anglefrom.IsEnabled = true;
txtbox_angleto.IsEnabled = true;
}
there, I hope that's useful
|
|
|
|
|
Do a search on XAML templates, you can do most of what you are doing with a template and triggers....
Google Friendly search: 'xaml templates WPF C# .NET site:microsoft.com'
|
|
|
|
|
I know, the test was to see if I could do it in code behind. Personally I have the feeling it is more flexible.
|
|
|
|
|
I have a WPF app with sqlserver 2008 database. I have several textboxes bound to date fields in the database as so :
TextBox Height="28" Name="textBoxApprovedDate" Width="120" Text="{Binding Path=ApprovedDate,StringFormat=dd/MM/yyyy}
The output from the database is fine, but it will not allow me to input a date in UK format ie dd/MM/yyyy.
How can I solve this?
TIA Mike
|
|
|
|
|
Have a look at the datepicker control[^]. You can set the cultureInfo to en-UK if they have such a property available.
|
|
|
|
|
Hi,
Another problem with VS 2008 WPF designer. Program runs fine, but designer won't load the UI. Here is the shortest possible example to demonstrate the problem.
App
<pre>
<Application x:Class="UCTester.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Window1.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources\Styles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
</pre>
Window1
<pre>
<Window x:Class="UCTester.Window1"
xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation
xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
xmlns:local="clr-namespace:UCTester"
Title="Window1" Height="300" Width="300">
<DockPanel>
<local:GridViewer/>
</DockPanel>
</Window>
</pre>
GridViewer
<pre>
<UserControl x:Class="UCTester.GridViewer" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300">
<Border Style="{StaticResource stlListViewBorder}"></Border>
</UserControl>
</pre>
Styles
<pre>
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="stlListViewBorder" TargetType="{x:Type Border}">
</Style>
</ResourceDictionary>
</pre>
Now, in the GridViewer, if all you have is <Border></Border>, all is good. The code runs, and Window1 loads in designer. If, however, in the GridViewer, <Border></Border> is replaced by <Border Style="{StaticResource stlListViewBorder}"></Border>, the code still runs, but Window1 no longer loads in the designer.
Why? What am I missing? Or is this a bug in WPF? If someone could figure this out it would be really helpful. Problem is, if the designer is this problematic when you are dealing with code this simple, it will be tough to use as a tool when writing production code.
Your thoughts will be greatly appreciated.
Peter Battelino
|
|
|
|
|
Hi
There is a list box with some items in it. Also there is a grid with 3x3 matrix. The user will be dragging an item and dropping on one the cells of grid.
Most of the samples I found are about dragging-dropping from one listbox to another listbox. But I want to drop in one cell of grid. How can I acheive this?
Please advise. thanks
PJ
Follow your goals, Means will follow you ---Gandhi---
|
|
|
|
|
I think this might have to do with FrameworkElements and FrameworkContentElements have a look at my tip/trick
Build a bridge between FrwmeworkElement and FrameworkContentElement[^]
it might help, but this is just a buck wild shot guess. There is also a link to the main article that I get the info from on drag and drop between these elements.
~TheArch
|
|
|
|
|
Hi
I am trying to develop a multi player game over the internet. A 2 to 4 players game in WPF.
1. Since I want to make it available via browser also at some point, is "WPF-Browser Application" a good choice?
2. What approach I can follow to maintain the connectivity between players? Peer to peer or do I need to maintain a server in between all players?
3. How can I transfer the information across all instances and maintain data state?
Please advise. thanks
PJ
Follow your goals, Means will follow you ---Gandhi---
|
|
|
|
|
If you use peer-to-peer, at least one player in every peer-to-peer
pair is going to need to be a "server" to esatablish a connection...
Do you want users to have to configure firewalls and or HTTP
servers (or similar) just to play the game?
I would think a server would make items 2 and 3 much easier
on the users. Using an HTTP server is best, since most
machines are configured to allow internet access. And .NET
makes it easy to implement such servers.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|