M
moondaddy
I'm posting code for a user control ( FunctionConnectorSelector) below which
has 3 content controls in it. each content control uses a style from a
resource dictionary merged into the app.xaml file. each control has a
border with another style, and each border has a unique path inside of it.
I need to dynamically add these content controls using c# at runtime and am
having trouble referencing the styles and adding the path into the border.
this is the suto code I want to use
ContentControl cc = new ContentControl();
cc.style = "HorizontalLineConnectorButton";
Border bdr = new Border();
dbr.style = "FunctionConnectorSelectorButtonStyle";
cc.content = dbr;
//add first polyline
PathGeometry geometry = new PathGeometry();
PathFigure figure = new PathFigure();
figure.StartPoint = linePoints[0];
linePoints.Remove(linePoints[0]);
figure.Segments.Add(new PolyLineSegment(linePoints, false)); // or true
geometry.Figures.Add(figure);
// add second polyline
figure = new PathFigure();
figure.StartPoint = linePoints2[0];
linePoints.Remove(linePoints2[0]);
figure.Segments.Add(new PolyLineSegment(linePoints2, false)); // or true
geometry.Figures.Add(figure);
// or add path data something like this:
//path.Data="M0,2 L3,2 L3,6 L0,6 M3,4 L6,4 M9,2 L6,2 L6,6 L9,6"
dbr.content = geometry;
Below is the xaml for what I'm trying to do with c#. Note, I will start
with the user control "FunctionConnectorSelector" and add everything else
with c#.
<Canvas x:Class="DiagramTools.Connectors.FunctionConnectorSelector"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:c="clr-namespace
iagramTools.Connectors"
mc:Ignorable="d"
d
esignWidth="11" d
esignHeight="33.512"
Height="60" Width="30" Background="Transparent">
<!-- Single Line Connection-->
<ContentControl Name="btnLine" Width="11" Height="10" Canvas.Left="12"
Canvas.Top="13" Visibility="Hidden" >
<Border Style="{DynamicResource
FunctionConnectorSelectorButtonStyle}">
<Path Stroke="#FF007182" StrokeThickness="1" Data="M2,4 L7,4" />
</Border>
</ContentControl>
<!-- One to Many Connection-->
<ContentControl Name="btnOtM" Width="11" Height="10" Canvas.Left="12"
Canvas.Top="25" Visibility="Hidden" >
<Border Style="{DynamicResource
FunctionConnectorSelectorButtonStyle}" >
<Path Stroke="#FF007182" StrokeThickness="1" Data="M2,2 L5,2
L5,6 L2,6 M5,4 L8,4" />
</Border>
</ContentControl>
<!-- Many to Many Connection-->
<ContentControl Name="btnMtM" Width="11" Height="10" Canvas.Left="12"
Canvas.Top="37" Visibility="Hidden" >
<Border Style="{DynamicResource
FunctionConnectorSelectorButtonStyle}">
<Path Stroke="#FF007182" StrokeThickness="1" Data="M0,2 L3,2
L3,6 L0,6 M3,4 L6,4 M9,2 L6,2 L6,6 L9,6" />
</Border>
</ContentControl>
</Canvas>
any recomendations and sample code would be awsome. thanks.
has 3 content controls in it. each content control uses a style from a
resource dictionary merged into the app.xaml file. each control has a
border with another style, and each border has a unique path inside of it.
I need to dynamically add these content controls using c# at runtime and am
having trouble referencing the styles and adding the path into the border.
this is the suto code I want to use
ContentControl cc = new ContentControl();
cc.style = "HorizontalLineConnectorButton";
Border bdr = new Border();
dbr.style = "FunctionConnectorSelectorButtonStyle";
cc.content = dbr;
//add first polyline
PathGeometry geometry = new PathGeometry();
PathFigure figure = new PathFigure();
figure.StartPoint = linePoints[0];
linePoints.Remove(linePoints[0]);
figure.Segments.Add(new PolyLineSegment(linePoints, false)); // or true
geometry.Figures.Add(figure);
// add second polyline
figure = new PathFigure();
figure.StartPoint = linePoints2[0];
linePoints.Remove(linePoints2[0]);
figure.Segments.Add(new PolyLineSegment(linePoints2, false)); // or true
geometry.Figures.Add(figure);
// or add path data something like this:
//path.Data="M0,2 L3,2 L3,6 L0,6 M3,4 L6,4 M9,2 L6,2 L6,6 L9,6"
dbr.content = geometry;
Below is the xaml for what I'm trying to do with c#. Note, I will start
with the user control "FunctionConnectorSelector" and add everything else
with c#.
<Canvas x:Class="DiagramTools.Connectors.FunctionConnectorSelector"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:c="clr-namespace

mc:Ignorable="d"
d


Height="60" Width="30" Background="Transparent">
<!-- Single Line Connection-->
<ContentControl Name="btnLine" Width="11" Height="10" Canvas.Left="12"
Canvas.Top="13" Visibility="Hidden" >
<Border Style="{DynamicResource
FunctionConnectorSelectorButtonStyle}">
<Path Stroke="#FF007182" StrokeThickness="1" Data="M2,4 L7,4" />
</Border>
</ContentControl>
<!-- One to Many Connection-->
<ContentControl Name="btnOtM" Width="11" Height="10" Canvas.Left="12"
Canvas.Top="25" Visibility="Hidden" >
<Border Style="{DynamicResource
FunctionConnectorSelectorButtonStyle}" >
<Path Stroke="#FF007182" StrokeThickness="1" Data="M2,2 L5,2
L5,6 L2,6 M5,4 L8,4" />
</Border>
</ContentControl>
<!-- Many to Many Connection-->
<ContentControl Name="btnMtM" Width="11" Height="10" Canvas.Left="12"
Canvas.Top="37" Visibility="Hidden" >
<Border Style="{DynamicResource
FunctionConnectorSelectorButtonStyle}">
<Path Stroke="#FF007182" StrokeThickness="1" Data="M0,2 L3,2
L3,6 L0,6 M3,4 L6,4 M9,2 L6,2 L6,6 L9,6" />
</Border>
</ContentControl>
</Canvas>
any recomendations and sample code would be awsome. thanks.