473,399 Members | 4,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Multibinding for Polyline points doesnt reflect

1
Well i am providing you code for a sample program. Here i have a line which needs to have an arrow head so i have visual brush which contains a line and a polyline which draws the arrow head.I have two converters named StrokeConverter and ArrowConverter which is used to provide the stroke thickness and draw the arrow respectively. I have four textbox which are binded to the lines x1,y1,x2,y2 four changing the lines position on runtime as i need to provide user the flexibility to rotate and reposition the line.

Expand|Select|Wrap|Line Numbers
  1. Windows.xaml:-
  2.  
  3. <Window x:Class="Marker_new.MainWindow"
  4.         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  5.         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  6.         xmlns:my="clr-namespace:Marker_new"
  7.         Title="MainWindow" Height="550" Width="525">
  8.  
  9.     <Window.Resources>
  10.         <my:ArrowConverter x:Key="ArrowHead"/>
  11.         <my:StrokeConverter x:Key="Stroke"/>
  12.     </Window.Resources>
  13.     <Canvas Background="AliceBlue">
  14.         <Line x:Name="arrowLine" X1="-100" Y1="0" X2="10" Y2="200"  StrokeThickness="20" Canvas.Left="253" Canvas.Top="48" >
  15.             <Line.Stroke>
  16.                 <VisualBrush Stretch="None" >
  17.                     <VisualBrush.Visual>
  18.                         <Canvas>
  19.                             <Line x:Name="Line_Arrow" Stroke="Gray"  StrokeThickness="{Binding StrokeThickness,RelativeSource={RelativeSource FindAncestor,AncestorLevel=1,AncestorType={x:Type Line}},Converter={StaticResource Stroke}, ConverterParameter=Line_Arrow}" X1="{Binding X1,RelativeSource={RelativeSource FindAncestor,AncestorLevel=1,AncestorType={x:Type Line}}}" X2="{Binding X2,RelativeSource={RelativeSource FindAncestor,AncestorLevel=1,AncestorType={x:Type Line}}}" Y1="{Binding Y1,RelativeSource={RelativeSource FindAncestor,AncestorLevel=1,AncestorType={x:Type Line}}}" Y2="{Binding Y2,RelativeSource={RelativeSource FindAncestor,AncestorLevel=1,AncestorType={x:Type Line}}}"  />
  20.                             <Polyline x:Name="ArrowStart"  Stroke="Black" StrokeThickness="{Binding ElementName=Line_Arrow,Path=StrokeThickness}" >
  21.                                 <Polyline.Points>
  22.                                     <MultiBinding Converter="{StaticResource ArrowHead}" ConverterParameter="ArrowStart" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" >
  23.                                         <Binding Path="StrokeThickness" RelativeSource="{RelativeSource Mode=FindAncestor,AncestorLevel=1,AncestorType={x:Type Line}}" />
  24.                                         <Binding Path="X1" RelativeSource="{RelativeSource Mode=FindAncestor,AncestorLevel=1,AncestorType={x:Type Line}}" />
  25.                                         <Binding Path="X2" RelativeSource="{RelativeSource Mode=FindAncestor,AncestorLevel=1,AncestorType={x:Type Line}}"/>
  26.                                         <Binding Path="Y1" RelativeSource="{RelativeSource Mode=FindAncestor,AncestorLevel=1,AncestorType={x:Type Line}}"/>
  27.                                         <Binding Path="Y2" RelativeSource="{RelativeSource Mode=FindAncestor,AncestorLevel=1,AncestorType={x:Type Line}}"/>
  28.                                     </MultiBinding>
  29.                                 </Polyline.Points>
  30.  
  31.                             </Polyline>
  32.  
  33.                         </Canvas>
  34.                     </VisualBrush.Visual>
  35.                 </VisualBrush>
  36.             </Line.Stroke>
  37.         </Line>
  38.         <Polyline Points="16.5882797876383,13.3816384544783 15,0 28.2174998970398,2.62460985328183" Stroke="Red" StrokeThickness="2" Canvas.Left="44" Canvas.Top="35" />
  39.         <TextBox Text="{Binding ElementName=arrowLine,Path=X1}" Canvas.Left="310" Canvas.Top="12" Height="28" Name="textBox1" Width="57" />
  40.         <TextBox Text="{Binding ElementName=arrowLine,Path=Y1, Mode=TwoWay}" Canvas.Left="434" Canvas.Top="12" Height="28" Name="textBox2" Width="57" />
  41.         <TextBox Text="{Binding ElementName=arrowLine,Path=X2,Mode=TwoWay}" Canvas.Left="310" Canvas.Top="70" Height="28" Name="textBox3" Width="57" />
  42.         <TextBox Text="{Binding ElementName=arrowLine,Path=Y2,Mode=TwoWay}" Canvas.Left="434" Canvas.Top="70" Height="28" Name="textBox4" Width="57" />
  43.         <Label Canvas.Left="253" Canvas.Top="12" Content="X1" Height="28" Name="label1" />
  44.         <Label Canvas.Left="382" Canvas.Top="12" Content="Y1" Height="28" Name="label2" />
  45.         <Label Canvas.Left="253" Canvas.Top="68" Content="X2" Height="28" Name="label3" />
  46.         <Label Canvas.Left="382" Canvas.Top="68" Content="Y2" Height="28" Name="label4" />
  47.     </Canvas>
  48. </Window>
  49. StrokeConverter.cs:-
  50.  
  51. using System;
  52. using System.Collections.Generic;
  53. using System.Linq;
  54. using System.Text;
  55. using System.Windows.Data;
  56.  
  57. namespace Marker_new
  58. {
  59.     class StrokeConverter : IValueConverter
  60.     {
  61.         public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  62.         {
  63.             switch ((string)parameter)
  64.             {
  65.                 case "Line_Square":
  66.                 case "Line_Ellipse":
  67.                     return ((double)value - (double)1) / 3;
  68.                     break;
  69.                 case "Line_Triangle":
  70.                     return ((((double)value) / (2 * Math.Sin(Math.PI / 5)) - (double)1)) / 3;
  71.                 case "Line_Arrow":
  72.  
  73.                     return ((double)value - 2 * Math.Sin(Math.PI / 5)) / (6 * Math.Sin(Math.PI / 5) + (double)1);
  74.                     break;
  75.                 default:
  76.                     return null;
  77.             }
  78.  
  79.         }
  80.  
  81.         public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  82.         {
  83.             throw new NotImplementedException();
  84.         }
  85.     }
  86. }
  87. ArrowConverter.cs:-
  88.  
  89. using System;
  90. using System.Collections.Generic;
  91. using System.Linq;
  92. using System.Text;
  93. using System.Windows.Data;
  94. using System.Windows.Media;
  95. using System.Windows;
  96.  
  97. namespace Marker_new
  98. {
  99.     public class ArrowConverter : IMultiValueConverter
  100.     {
  101.         PointCollection _ptCollectionsStart = new PointCollection();
  102.         PointCollection _ptCollectionsEnd = new PointCollection();
  103.         Point pt1;
  104.         Point pt2;
  105.         public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  106.         {
  107.  
  108.                 double _strokethickness;
  109.                 _strokethickness = ((double)values[0] - 2 * Math.Sin(Math.PI / 5)) / (6 * Math.Sin(Math.PI / 5) + (double)1);
  110.                 double _triangleLength = 3 * _strokethickness + (double)1;
  111.                 pt1.X = (double)values[1];
  112.                 pt1.Y = (double)values[3];
  113.                 pt2.X = (double)values[2];
  114.                 pt2.Y = (double)values[4];
  115.                 switch ((string)parameter)
  116.                 {
  117.                     case "ArrowStart":
  118.                         _ptCollectionsStart.Clear();
  119.                         double ArrowLength = 3 * _strokethickness + 1;
  120.                         Matrix matx = new Matrix();
  121.                         Vector vect = pt2 - pt1;
  122.                         vect.Normalize();
  123.                         vect *= ArrowLength;
  124.                         matx.Rotate(36);
  125.                         _ptCollectionsStart.Add(pt1  + vect * matx);
  126.                         _ptCollectionsStart.Add(pt1);
  127.                         matx.Rotate(-72);
  128.                         _ptCollectionsStart.Add(pt1 + vect * matx);
  129.                         return _ptCollectionsStart;
  130.                         break;
  131.  
  132.                     //case "ArrowEnd":
  133. // not implemented so far
  134.                     //    break;
  135.                     default:
  136.                         return 10;
  137.                 }
  138.  
  139.  
  140.         }
  141.  
  142.         public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
  143.         {
  144.             throw new NotImplementedException();
  145.         }
  146.     }
  147. }=


For the first tym its is coming fine but when i change the value of line points using textbox at runtime the arrowconverter is getting called and its providing changed values for arrow to be drawn but its not getting reflected. Let me know whats the issue.
Dec 23 '12 #1
0 1948

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: JS | last post by:
Can somebody explain how to get the tablespace out of quiesce mode? I am executing on each node of my EEE Win2K system: db2 quiesece tablespace for table schema.tablename RESET I get the...
3
by: Arun Nair | last post by:
''' Can anyone help me with this program it just takes probability of the first team and runs the program doesnt takes the probability of the second team even though specified''' from random...
2
by: moondaddy | last post by:
I'm creating a sample project where I will adorn a Polyline with thumbs so I can resize it by dragging its ends (and points) around. This is similar to some projects I've posted using a...
0
by: =?Utf-8?B?YWxleF9jYXJvMQ==?= | last post by:
Hi, I would like to use a multibinding to determine the fill value of my rectangle style. <Style x:Key="StyleRect" TargetType="{x:Type Rectangle}"> <Setter Property="Fill"> <Setter.Value>...
2
by: sarah.kidd | last post by:
Hello I was wondering if someone could please help me. I have created a google map: http://www.cancerpatientgis.com/markers%20test/HospPat_markerstest.html
10
by: moondaddy | last post by:
Hi, I have 3 tiny content controls and each has a Path in it to draw some lines. These need to be very small and I'm having trouble making the lines clear. the lines have a stroke thickness of "1",...
1
by: Linda Liu[MSFT] | last post by:
Hi George, Thank you for posting! This is a quick note to let you know that I am doing research on this issue and will get back to you ASAP. I appreciate your patience! Sincerely,
0
by: Chris Jobson | last post by:
>I have a sample similar to a previous post where I was binding a line end Not sure if I'm right, but I think the problem is that the data binding doesn't go through the property wrapper, but...
6
by: raylopez99 | last post by:
This language C# is more primitive than I thought. I just found out that C#2.0 does not support polyline (see below), a very useful feature for connecting points with a line automatically. Only...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.