Ending xml tag in treeview control - wpf

I'm currently working on a simple xml viewer control to display some xml files with easy navigation possibilities, like when you open a xml file in the internet explorer.
For this I found a nice control in the msdn forums:
<UserControl x:Class="WpfApplication1.CustomControl.Viewer"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:xmlstack="clr-namespace:System.Xml;assembly=System.Xml">
<UserControl.Resources>
<SolidColorBrush x:Key="xmlValueBrush" Color="Blue" />
<SolidColorBrush x:Key="xmAttributeBrush" Color="Red" />
<SolidColorBrush x:Key="xmlTagBrush" Color="DarkMagenta" />
<SolidColorBrush x:Key="xmlMarkBrush" Color="Blue" />
<DataTemplate x:Key="attributeTemplate">
<StackPanel Margin="3,0,0,0"
HorizontalAlignment="Center"
Orientation="Horizontal">
<TextBlock Foreground="{StaticResource xmAttributeBrush}" Text="{Binding Path=Name}" />
<TextBlock Foreground="{StaticResource xmlMarkBrush}" Text="="" />
<TextBlock Foreground="{StaticResource xmlValueBrush}" Text="{Binding Path=Value}" />
<TextBlock Foreground="{StaticResource xmlMarkBrush}" Text=""" />
</StackPanel>
</DataTemplate>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="IsExpanded" Value="True" />
</Style>
<HierarchicalDataTemplate x:Key="treeViewTemplate" ItemsSource="{Binding XPath=child::node()}">
<StackPanel Margin="3,0,0,0"
HorizontalAlignment="Center"
Orientation="Horizontal">
<TextBlock x:Name="startTag"
HorizontalAlignment="Center"
Foreground="{StaticResource xmlMarkBrush}"
Text="<" />
<TextBlock x:Name="xmlTag"
Margin="0"
HorizontalAlignment="Center"
Foreground="{StaticResource xmlTagBrush}"
Text="{Binding Path=Name}" />
<ItemsControl HorizontalAlignment="Center"
ItemsSource="{Binding Path=Attributes}"
ItemTemplate="{StaticResource attributeTemplate}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
<TextBlock x:Name="endTag"
HorizontalAlignment="Center"
Foreground="{StaticResource xmlMarkBrush}"
Text=">" />
</StackPanel>
<HierarchicalDataTemplate.Triggers>
<DataTrigger Binding="{Binding NodeType}">
<DataTrigger.Value>
<xmlstack:XmlNodeType>Text</xmlstack:XmlNodeType>
</DataTrigger.Value>
<Setter TargetName="xmlTag" Property="Text" Value="{Binding InnerText}" />
<Setter TargetName="xmlTag" Property="Foreground" Value="Blue" />
<Setter TargetName="startTag" Property="Visibility" Value="Collapsed" />
<Setter TargetName="endTag" Property="Visibility" Value="Collapsed" />
</DataTrigger>
<DataTrigger Binding="{Binding HasChildNodes}" Value="False">
<Setter TargetName="endTag" Property="Text" Value=" />" />
</DataTrigger>
</HierarchicalDataTemplate.Triggers>
</HierarchicalDataTemplate>
</UserControl.Resources>
<Grid>
<TreeView Name="xmlTree"
Grid.Row="2"
Grid.ColumnSpan="2"
ItemTemplate="{StaticResource treeViewTemplate}" />
</Grid>
</UserControl>
Code-Behind:
using System.Windows.Controls;
using System.Windows.Data;
using System.Xml;
namespace WpfApplication1.CustomControl
{
/// <summary>
/// Interaction logic for Viewer.xaml
/// </summary>
public partial class Viewer : UserControl
{
private XmlDocument _xmldocument;
public Viewer()
{
InitializeComponent();
}
public XmlDocument xmlDocument
{
get { return _xmldocument; }
set
{
_xmldocument = value;
BindXMLDocument();
}
}
private void BindXMLDocument()
{
if (_xmldocument == null)
{
xmlTree.ItemsSource = null;
return;
}
XmlDataProvider provider = new XmlDataProvider();
provider.Document = _xmldocument;
Binding binding = new Binding();
binding.Source = provider;
binding.XPath = "child::node()";
xmlTree.SetBinding(TreeView.ItemsSourceProperty, binding);
}
}
}
My problem now is that I want to display the ending tag of child nodes, in the following example marked with stars:
<root>
<node>Test*</node>*
*</root>*
I don't know how to realize this, are there good suggestions?
Thank you in advance.

I solved it by using the WebBrowser control.
I found no good solution with TreeView, but I'm full satisfied with this code, because it's full MVVM:
Create a dependency property for WebBrowser controls called BindableXmlData:
Public Class AttachedWebBrowserProperties
#Region "BindableXmlDataProperty"
Public Shared ReadOnly BindableXmlDataProperty As DependencyProperty = _
DependencyProperty.RegisterAttached("BindableXmlData", _
GetType(String), _
GetType(AttachedWebBrowserProperties), _
New UIPropertyMetadata(Nothing, AddressOf BindableXmlDataPropertyChanged))
Public Shared Function GetBindableXmlData(ByVal obj As DependencyObject) As ICommand
Return CType(obj.GetValue(BindableXmlDataProperty), ICommand)
End Function
Public Shared Sub SetBindableXmlData(ByVal obj As DependencyObject, ByVal value As String)
obj.SetValue(BindableXmlDataProperty, value)
End Sub
Public Shared Sub BindableXmlDataPropertyChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
Dim browser As WebBrowser = TryCast(d, WebBrowser)
If browser IsNot Nothing Then
Dim xmldata As String = TryCast(e.NewValue, String)
If xmldata IsNot Nothing Then
browser.NavigateToString(xmldata)
End If
End If
End Sub
#End Region
End Class
Then add a new file to your solution called XmlToHtmlStylesheet.xslt as embedded resource with following content:
<!--
|
| XSLT REC Compliant Version of IE5 Default Stylesheet
|
| Original version by Jonathan Marsh (jmarsh#xxxxxxxxxxxxx)
| http://msdn.microsoft.com/xml/samples/defaultss/defaultss.xsl
|
| Conversion to XSLT 1.0 REC Syntax by Steve Muench (smuench#xxxxxxxxxx)
|
+-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="no" method="html"/>
<xsl:template match="/">
<HTML>
<HEAD>
<SCRIPT>
<xsl:comment>
<![CDATA[
function f(e){
if (e.className=="ci") {
if (e.children(0).innerText.indexOf("\n")>0) fix(e,"cb");
}
if (e.className=="di") {
if (e.children(0).innerText.indexOf("\n")>0) fix(e,"db");
} e.id="";
}
function fix(e,cl){
e.className=cl;
e.style.display="block";
j=e.parentElement.children(0);
j.className="c";
k=j.children(0);
k.style.visibility="visible";
k.href="#";
}
function ch(e) {
mark=e.children(0).children(0);
if (mark.innerText=="+") {
mark.innerText="-";
for (var i=1;i<e.children.length;i++) {
e.children(i).style.display="block";
}
}
else if (mark.innerText=="-") {
mark.innerText="+";
for (var i=1;i<e.children.length;i++) {
e.children(i).style.display="none";
}
}
}
function ch2(e) {
mark=e.children(0).children(0);
contents=e.children(1);
if (mark.innerText=="+") {
mark.innerText="-";
if (contents.className=="db"||contents.className=="cb") {
contents.style.display="block";
}
else {
contents.style.display="inline";
}
}
else if (mark.innerText=="-") {
mark.innerText="+";
contents.style.display="none";
}
}
function cl() {
e=window.event.srcElement;
if (e.className!="c") {
e=e.parentElement;
if (e.className!="c") {
return;
}
}
e=e.parentElement;
if (e.className=="e") {
ch(e);
}
if (e.className=="k") {
ch2(e);
}
}
function ex(){}
function h(){window.status=" ";}
document.onclick=cl;
]]>
</xsl:comment>
</SCRIPT>
<STYLE>
BODY {font:x-small 'Verdana'; margin-right:1.5em}
.c {cursor:hand}
.b {color:red; font-family:'Courier New'; font-weight:bold;
text-decoration:none}
.e {margin-left:1em; text-indent:-1em; margin-right:1em}
.k {margin-left:1em; text-indent:-1em; margin-right:1em}
.t {color:#990000}
.xt {color:#990099}
.ns {color:red}
.dt {color:green}
.m {color:blue}
.tx {font-weight:bold}
.db {text-indent:0px; margin-left:1em; margin-top:0px;
margin-bottom:0px;padding-left:.3em;
border-left:1px solid #CCCCCC; font:small Courier}
.di {font:small Courier}
.d {color:blue}
.pi {color:blue}
.cb {text-indent:0px; margin-left:1em; margin-top:0px;
margin-bottom:0px;padding-left:.3em; font:small Courier;
color:#888888}
.ci {font:small Courier; color:#888888}
PRE {margin:0px; display:inline}
</STYLE>
</HEAD>
<BODY class="st">
<xsl:apply-templates/>
</BODY>
</HTML>
</xsl:template>
<xsl:template match="processing-instruction()">
<DIV class="e">
<SPAN class="b">
<xsl:call-template name="entity-ref">
<xsl:with-param name="name">nbsp</xsl:with-param>
</xsl:call-template>
</SPAN>
<SPAN class="m">
<xsl:text><?</xsl:text>
</SPAN>
<SPAN class="pi">
<xsl:value-of select="name(.)"/>
<xsl:value-of select="."/>
</SPAN>
<SPAN class="m">
<xsl:text>?></xsl:text>
</SPAN>
</DIV>
</xsl:template>
<xsl:template match="processing-instruction('xml')">
<DIV class="e">
<SPAN class="b">
<xsl:call-template name="entity-ref">
<xsl:with-param name="name">nbsp</xsl:with-param>
</xsl:call-template>
</SPAN>
<SPAN class="m">
<xsl:text><?</xsl:text>
</SPAN>
<SPAN class="pi">
<xsl:text>xml </xsl:text>
<xsl:for-each select="#*">
<xsl:value-of select="name(.)"/>
<xsl:text>="</xsl:text>
<xsl:value-of select="."/>
<xsl:text>" </xsl:text>
</xsl:for-each>
</SPAN>
<SPAN class="m">
<xsl:text>?></xsl:text>
</SPAN>
</DIV>
</xsl:template>
<xsl:template match="#*">
<SPAN>
<xsl:attribute name="class">
<xsl:if test="xsl:*/#*">
<xsl:text>x</xsl:text>
</xsl:if>
<xsl:text>t</xsl:text>
</xsl:attribute>
<xsl:value-of select="name(.)"/>
</SPAN>
<SPAN class="m">="</SPAN>
<B>
<xsl:value-of select="."/>
</B>
<SPAN class="m">"</SPAN>
</xsl:template>
<xsl:template match="text()">
<DIV class="e">
<SPAN class="b"> </SPAN>
<SPAN class="tx">
<xsl:value-of select="."/>
</SPAN>
</DIV>
</xsl:template>
<xsl:template match="comment()">
<DIV class="k">
<SPAN>
<A STYLE="visibility:hidden" class="b" onclick="return false" onfocus="h()">-</A>
<SPAN class="m">
<xsl:text><!--</xsl:text>
</SPAN>
</SPAN>
<SPAN class="ci" id="clean">
<PRE>
<xsl:value-of select="."/>
</PRE>
</SPAN>
<SPAN class="b">
<xsl:call-template name="entity-ref">
<xsl:with-param name="name">nbsp</xsl:with-param>
</xsl:call-template>
</SPAN>
<SPAN class="m">
<xsl:text>--></xsl:text>
</SPAN>
<SCRIPT>f(clean);</SCRIPT>
</DIV>
</xsl:template>
<xsl:template match="*">
<DIV class="e">
<DIV STYLE="margin-left:1em;text-indent:-2em">
<SPAN class="b">
<xsl:call-template name="entity-ref">
<xsl:with-param name="name">nbsp</xsl:with-param>
</xsl:call-template>
</SPAN>
<SPAN class="m"><</SPAN>
<SPAN>
<xsl:attribute name="class">
<xsl:if test="xsl:*">
<xsl:text>x</xsl:text>
</xsl:if>
<xsl:text>t</xsl:text>
</xsl:attribute>
<xsl:value-of select="name(.)"/>
<xsl:if test="#*">
<xsl:text> </xsl:text>
</xsl:if>
</SPAN>
<xsl:apply-templates select="#*"/>
<SPAN class="m">
<xsl:text>/></xsl:text>
</SPAN>
</DIV>
</DIV>
</xsl:template>
<xsl:template match="*[node()]">
<DIV class="e">
<DIV class="c">
<A class="b" href="#" onclick="return false" onfocus="h()">-</A>
<SPAN class="m"><</SPAN>
<SPAN>
<xsl:attribute name="class">
<xsl:if test="xsl:*">
<xsl:text>x</xsl:text>
</xsl:if>
<xsl:text>t</xsl:text>
</xsl:attribute>
<xsl:value-of select="name(.)"/>
<xsl:if test="#*">
<xsl:text> </xsl:text>
</xsl:if>
</SPAN>
<xsl:apply-templates select="#*"/>
<SPAN class="m">
<xsl:text>></xsl:text>
</SPAN>
</DIV>
<DIV>
<xsl:apply-templates/>
<DIV>
<SPAN class="b">
<xsl:call-template name="entity-ref">
<xsl:with-param name="name">nbsp</xsl:with-param>
</xsl:call-template>
</SPAN>
<SPAN class="m">
<xsl:text></</xsl:text>
</SPAN>
<SPAN>
<xsl:attribute name="class">
<xsl:if test="xsl:*">
<xsl:text>x</xsl:text>
</xsl:if>
<xsl:text>t</xsl:text>
</xsl:attribute>
<xsl:value-of select="name(.)"/>
</SPAN>
<SPAN class="m">
<xsl:text>></xsl:text>
</SPAN>
</DIV>
</DIV>
</DIV>
</xsl:template>
<xsl:template match="*[text() and not (comment() or processing-instruction())]">
<DIV class="e">
<DIV STYLE="margin-left:1em;text-indent:-2em">
<SPAN class="b">
<xsl:call-template name="entity-ref">
<xsl:with-param name="name">nbsp</xsl:with-param>
</xsl:call-template>
</SPAN>
<SPAN class="m">
<xsl:text><</xsl:text>
</SPAN>
<SPAN>
<xsl:attribute name="class">
<xsl:if test="xsl:*">
<xsl:text>x</xsl:text>
</xsl:if>
<xsl:text>t</xsl:text>
</xsl:attribute>
<xsl:value-of select="name(.)"/>
<xsl:if test="#*">
<xsl:text> </xsl:text>
</xsl:if>
</SPAN>
<xsl:apply-templates select="#*"/>
<SPAN class="m">
<xsl:text>></xsl:text>
</SPAN>
<SPAN class="tx">
<xsl:value-of select="."/>
</SPAN>
<SPAN class="m"></</SPAN>
<SPAN>
<xsl:attribute name="class">
<xsl:if test="xsl:*">
<xsl:text>x</xsl:text>
</xsl:if>
<xsl:text>t</xsl:text>
</xsl:attribute>
<xsl:value-of select="name(.)"/>
</SPAN>
<SPAN class="m">
<xsl:text>></xsl:text>
</SPAN>
</DIV>
</DIV>
</xsl:template>
<xsl:template match="*[*]" priority="20">
<DIV class="e">
<DIV STYLE="margin-left:1em;text-indent:-2em" class="c">
<A class="b" href="#" onclick="return false" onfocus="h()">-</A>
<SPAN class="m"><</SPAN>
<SPAN>
<xsl:attribute name="class">
<xsl:if test="xsl:*">
<xsl:text>x</xsl:text>
</xsl:if>
<xsl:text>t</xsl:text>
</xsl:attribute>
<xsl:value-of select="name(.)"/>
<xsl:if test="#*">
<xsl:text> </xsl:text>
</xsl:if>
</SPAN>
<xsl:apply-templates select="#*"/>
<SPAN class="m">
<xsl:text>></xsl:text>
</SPAN>
</DIV>
<DIV>
<xsl:apply-templates/>
<DIV>
<SPAN class="b">
<xsl:call-template name="entity-ref">
<xsl:with-param name="name">nbsp</xsl:with-param>
</xsl:call-template>
</SPAN>
<SPAN class="m">
<xsl:text></</xsl:text>
</SPAN>
<SPAN>
<xsl:attribute name="class">
<xsl:if test="xsl:*">
<xsl:text>x</xsl:text>
</xsl:if>
<xsl:text>t</xsl:text>
</xsl:attribute>
<xsl:value-of select="name(.)"/>
</SPAN>
<SPAN class="m">
<xsl:text>></xsl:text>
</SPAN>
</DIV>
</DIV>
</DIV>
</xsl:template>
<xsl:template name="entity-ref">
<xsl:param name="name"/>
<xsl:text disable-output-escaping="yes">&</xsl:text>
<xsl:value-of select="$name"/>
<xsl:text>;</xsl:text>
</xsl:template>
</xsl:stylesheet>
Create a new window (or in my case, a usercontrol):
<UserControl x:Class="AdditionalXmlView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ui="clr-namespace:MyApplication.Framework">
<WebBrowser ui:AttachedWebBrowserProperties.BindableXmlData="{Binding XmlData}" />
</UserControl>
Create a viewmodel like this:
Imports System.Xml
Imports System.Xml.Xsl
Imports System.Text
Imports System.IO
Imports System.ComponentModel
Public Class AdditionalXmlViewModel
Implements INotifyPropertyChanged
Private _XmlData As String
Public Property XmlData() As String
Get
Return _XmlData
End Get
Set(ByVal value As String)
_XmlData = value
OnPropertyChanged("XmlData")
End Set
End Property
Public Sub LoadXmlData(ByVal xmlDocument As XmlDocument)
Dim sb As New StringBuilder(2500)
Dim xslt As New XslCompiledTransform()
Dim stylesheetStream As Stream = GetType(AdditionalXmlView).Assembly.GetManifestResourceStream("MyApplication.Framework.XmlToHtmlStylesheet.xslt")
If stylesheetStream IsNot Nothing Then
Dim xmlReader As XmlReader = xmlReader.Create(stylesheetStream)
xslt.Load(xmlReader)
Dim settings As New XmlWriterSettings()
Dim dest As XmlWriter = XmlWriter.Create(sb, settings)
xslt.Transform(xmlDocument, dest)
End If
XmlData = sb.ToString()
End Sub
Public Event PropertyChanged(ByVal sender As Object, ByVal e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
Public Sub OnPropertyChanged(ByVal propertyName As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
End Sub
End Class
Create your view and viewmodel and set the xmldata:
Public Class XYZ
Private additionalView As AdditionalXmlView
Private additionalViewModel As AdditionalXmlViewModel
Private Sub CreateInstances()
additionalViewModel = New AdditionalXmlViewModel()
additionalView = New AdditionalXmlView()
additionalView.DataContext = additionalViewModel
End Sub
Private Sub SetXmlDataOfAdditionalView()
Dim xmlDocument As New XmlDocument()
xmlDocument.Load("myXmlFile.xml")
additionalViewModel.LoadXmlData(xmlDocument)
End Sub
End Class

Related

Variables in script filled after second run of script

Can someone please provide some tip how to solve this issue with my script?
Script description:
Its script which creates HTML signature from GUI created in WPF.
Problem description:
First run script with WPF creates folder with right name, copy images and create HTML with right name but HTML file is blank only with images. After second run of script the folder, html file and images are filled right but with information from first run.
I guess it has something with $Global variables, because this issue is detected after i add in some $Global vars.
Thank you for any help.
PS1. script:
Add-Type -Name Window -Namespace Console -MemberDefinition
[DllImport("Kernel32.dll")]
public static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hWnd, Int32 nCmdShow);'
[Console.Window]::ShowWindow([Console.Window]::GetConsoleWindow(), 0)
#-------------------------------------------------------------#
#----Initial Declarations-------------------------------------#
#-------------------------------------------------------------#
Add-Type -AssemblyName PresentationCore, PresentationFramework
$Xaml = #"
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Width="647" Height="630" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:src="clr-namespace:ListBoxStyle">
<Window.Resources>
<Style x:Key="_ListBoxItemStyle" TargetType="ListBoxItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border Name="_Border" Padding="2" SnapsToDevicePixels="true">
<ContentPresenter/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter TargetName="_Border" Property="Background" Value="#18509c"/>
<Setter Property="Foreground" Value="White"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid Name="GTX_Podpis" Margin="-2,-1,2,1" MinWidth="1500" MinHeight="1000">
<Image HorizontalAlignment="Left" Height="112" VerticalAlignment="Top" Width="137" Margin="10.84375,11,0,0" Name="Gumotex" Source="\\gtxdc1\Skupiny\Posta podpisy\Husařík_Jakub\logo_gumotex.png"/>
<TextBox HorizontalAlignment="Left" BorderBrush="#18509c" BorderThickness="2" VerticalAlignment="Top" Height="30" Width="120" TextWrapping="Wrap" Margin="185,24,0,0" Name="TitulPred" Tag="TitulPred" Text="" ToolTip="TitulPřed"/>
<TextBox HorizontalAlignment="Left" BorderBrush="#18509c" BorderThickness="2" VerticalAlignment="Top" Height="30" Width="120" TextWrapping="Wrap" Margin="321,24,0,0" Name="TitulZa" Tag="TitulZa" Text="" ToolTip="TitulZa"/>
<TextBox HorizontalAlignment="Left" BorderBrush="#18509c" BorderThickness="2" VerticalAlignment="Top" Height="30" Width="181" TextWrapping="Wrap" Margin="187,76,0,0" Name="Jmeno" ToolTip="Jméno" Text="" Tag="Jmeno"/>
<TextBox HorizontalAlignment="Left" BorderBrush="#18509c" BorderThickness="2" VerticalAlignment="Top" Height="30" Width="181" TextWrapping="Wrap" Margin="187,133,0,0" Name="Prijmeni" Tag="Prijmeni" Text="" ToolTip="Přijmeni"/>
<TextBox HorizontalAlignment="Left" BorderBrush="#18509c" BorderThickness="2" VerticalAlignment="Top" Height="30" Width="181" TextWrapping="Wrap" Margin="189,183,0,0" Name="Funkce" Tag="Funkce" Text="" ToolTip="Funkce"/>
<TextBox HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="181" TextWrapping="Wrap" Margin="189,235,0,0" Name="Email" BorderBrush="#18509c" BorderThickness="2"/>
<TextBox HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="181" TextWrapping="Wrap" Margin="190,290,0,0" Name="Mobil" BorderBrush="#18509c" BorderThickness="2"/>
<TextBox HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="181" TextWrapping="Wrap" Margin="189,349,0,0" Name="PevnaLinka" BorderBrush="#18509c" BorderThickness="2"/>
<ListBox HorizontalAlignment="Left" BorderBrush="#18509c" BorderThickness="2" Height="88" VerticalAlignment="Top" Width="164" Margin="7,75,0,0" Name="Divize" Tag="Divize" ToolTip="Divize" Foreground="#000000" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto"
ItemContainerStyle="{DynamicResource _ListBoxItemStyle}"
>
<ListBoxItem Content="DIVIZE SERVICE"/>
<ListBoxItem Content="DIVIZE COATING"/>
<ListBoxItem Content="AUTOMOTIVE DIVISION"/>
<ListBoxItem Content="COATING DIVISION"/>
</ListBox>
<ListBox HorizontalAlignment="Left" BorderBrush="#18509c" BorderThickness="2" Height="304" VerticalAlignment="Top" Width="243" Margin="387,75,0,0" Name="Zavod" Tag="Závod" ToolTip="Závod" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto"
ItemContainerStyle="{DynamicResource _ListBoxItemStyle}"
>
<ListBoxItem Content="PRÁZDNÉ"/>
<ListBoxItem Content="ZÁVOD BŘECLAV"/>
<ListBoxItem Content="ZÁVOD TŘEBÍČ"/>
<ListBoxItem Content="ZÁVOD JAROMĚŘ"/>
<ListBoxItem Content="ZÁVOD MYJAVA"/>
<ListBoxItem Content="ZÁVOD ROŽNOV"/>
<ListBoxItem Content="PRODUCTION PLANT BRECLAV"/>
<ListBoxItem Content="PRODUCTION PLANT TREBIC"/>
<ListBoxItem Content="PRODUCTION PLANT JAROMER"/>
<ListBoxItem Content="PRODUCTION PLANT MYJAVA"/>
<ListBoxItem Content="PRODUCTION PLANT ROZNOV"/>
<ListBoxItem Content="ENGINEERING DEPARTMENT BRECLAV"/>
<ListBoxItem Content="ENGINEERING DEPARTMENT TREBIC"/>
<ListBoxItem Content="ENGINEERING DEPARTMENT JAROMER"/>
<ListBoxItem Content="ENGINEERING DEPARTMENT MYJAVA"/>
<ListBoxItem Content="ENGINEERING DEPARTMENT ROZNOV"/>
</ListBox>
<ListBox HorizontalAlignment="Left" BorderBrush="#18509c" BorderThickness="2" Height="109" VerticalAlignment="Top" Width="164" Margin="7,184,0,0" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto"
ItemContainerStyle="{DynamicResource _ListBoxItemStyle}" Name = "Adresa"
>
<ListBoxItem Content="BŘECLAV"/>
<ListBoxItem Content="TŘEBÍČ"/>
<ListBoxItem Content="JAROMĚŘ"/>
<ListBoxItem Content="MYJAVA"/>
<ListBoxItem Content="ROŽNOV"/>
</ListBox>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Adresa" Margin="9,164,0,0" Name="AdresaLabel"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Divize" Margin="8,54,0,0" Name="DivizeLabel"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="TitulPred" Margin="184,5,0,0" Name="TitulPredLabel"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Jméno" Margin="188,56,0,0" Name="JmenoLabel"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="TitulZa" Margin="321,5,0,0" Name="TitulZaLabel"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Přijmení" Margin="187,112,0,0" Name="PrijmeniLabel"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Funkce" Margin="188,164,0,0" Name="FunkceLabel"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Závod" Margin="388,55,0,0" Name="ZavodLabel"/>
<Button Content="Vytvoř podpis" HorizontalAlignment="Left" VerticalAlignment="Top" Width="224" Margin="6,527,0,0" Name="VytvorPodpisButton" Background="#18509c" Foreground="#efefef" Height="55" FontSize="15"/>
<Button Content="Zavřít" HorizontalAlignment="Left" VerticalAlignment="Top" Width="224" Margin="403,529,0,0" Height="55" Name="ZavritButton" Background="#18509c" Foreground="#ffffff" FontSize="15"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Email" Margin="189,214,0,0" Name="EmalLabel"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Mobil" Margin="190,267,0,0" Name="MobilLabel"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Pevná linka" Margin="189,327,0,0" Name="PevnaLinkaLabel"/>
</Grid>
</Window>
"#
#-------------------------------------------------------------#
#----Global variables-----------------------------------#
#-------------------------------------------------------------#
$Global:ZavodHTML
$Global:AdresaInHTML
# Břeclav
$Global:VarAdresaBreclavUlice = "Mládežnická 3062/3a"
$Global:VarAdresaBreclavMesto = "690 02 Břeclav"
$Global:VarAdresaBreclavStat = "Česká republika"
$Global:VarAdresaBreclav
# Jaroměř
$Global:VarAdresaJaromerUlice = "V Lužinách 113, Pražské Předměstí"
$Global:VarAdresaJaromerMesto = "551 01 Jaroměř"
$Global:VarAdresaJaromerStat = "Česká republika"
$Global:VarAdresaJaromer
# Třebíč
$Global:arAdresaTrebicUlice = "Žďárského 184"
$Global:VarAdresaTrebicvMesto = "674 01 Kožichovice"
$Global:VarAdresaTrebicvStat = "Česká republika"
$Global:VarAdresaTrebic
# Myjava
$Global:VarAdresaMyjavaUlice = "Prostredná 1227/9"
$Global:VarAdresaMyjavavMesto = "907 01 Myjava"
$Global:VarAdresaMyjavaStat = "Slovenská republika"
$Global:VarAdresaMyjava
# Rožnov
$Global:VarAdresaRoznovUlice = "Televizní 2614"
$Global:VarAdresaRoznovMesto = "756 61 Rožnov pod Radhoštěm"
$Global:VarAdresaRoznovStat = "Česká republika"
$Global:VarAdresaRoznov
# Právní odstavce
#...........................................................................................................................................................................
# Český odstavec
$HTMLTextPravoS = #"
Tato zpráva má pouze informativní charakter. Obsah této zprávy obchodní společnost GUMOTEX, akciová společnost, ani žádnou jinou osobu, která s ní tvoří koncern (dále jen "GUMOTEX"), nezavazuje. GUMOTEX nemá v úmyslu touto zprávou jakoukoliv smlouvu uzavřít, přijmout nabídku nebo uzavření jakékoliv smlouvy potvrdit a zpráva ani nezakládá jeho předsmluvní odpovědnost. Kterákoliv smlouva pro GUMOTEX závazná musí mít výhradně tištěnou písemnou formu, náležitosti dle příslušných právních předpisů a musí být podepsána osobou, která je za GUMOTEX oprávněna jednat nebo GUMOTEX zastupovat. Tato zpráva může obsahovat důvěrné informace. Pokud nejste jejím určeným příjemcem, jakékoliv její zveřejnění, kopírování, rozesílání nebo jiné užití jejího obsahu je přísně zakázáno. Nejste-li určeným příjemcem zprávy, informujte v takovém případě prosím ihned jejího odesílatele a poté zprávu, včetně případných příloh, bezodkladně z Vašeho zařízení smažte.
"#
# Anglický odstavec
$HTMLTextPravoENS =
#"
This e-mail message is intended only for informational purposes. The content of this message is not binding for neither the company GUMOTEX, akciová společnost, nor any other entity forming the GUMOTEX Group (hereinafter „GUMOTEX“). GUMOTEX does not intend to conclude any agreements, to accept any offers or to confirm the conclusion of any contracts via this message. This message shall not give rise to GUMOTEX precontractual liability. Any agreement binding GUMOTEX shall be in a written form and printed, shall comply with all statutory requirements and shall be signed by a person authorized to act on behalf of or for GUMOTEX. This e-mail message may contain confidential information. If you are not the intended recipient of this message, any disclosure, copying, distribution or use of its contents is strictly prohibited. Please notify the sender immediately and delete the message (including any attachments) from your system.
"#
#...........................................................................................................................................................................
#-------------------------------------------------------------#
#----HTML-----------------------------------------------------#
#-------------------------------------------------------------#
$HTML = #"
<!DOCTYPE html>
<html lang="cs">
<head>
<title>Mail signature</title>
<meta charset="Windows-1250">
<style>
a {
text-decoration: none;
color: #000000;
}
a:hover {
color: #20549A;
}
a:active {
color: #20549A;
</style>
</head>
<body>
<table>
<tr>
<td style="font-family: arial; font-weight: bold; color: #000000; font-size: 16px;">$($TitulPred.Text+$Jmeno.Text+" "+$Prijmeni.Text + $TitulZa.Text)</td>
</tr>
<td style="font-family: arial;font-size: 1px;"> </td>
</tr>
<tr>
<td style="font-family: arial; color: #434442; font-size: 14px;">$($Funkce.Text)</td>
</tr>
$Global:ZavodHTML
<tr>
<td style="font-family: arial; color: #20549A; font-weight: bold; font-size: 14px;">$(($Divize.SelectedItem.Content))</td>
</tr>
</tr>
<td style="font-family: arial;font-size: 10px;"> </td>
</tr>
<tr>
<td><img src="logo_gumotex.png" alt="GUMOTEX"></td>
</tr>
<td style="font-family: arial;font-size: 8px;"> </td>
</tr>
</tr>
</table>
<table>
<tr>
<td><img src="icon_envelope_2.png" alt="Email"></td>
<td style="vertical-align: middle;font-family: arial; color: #000000; font-size: 12px;"> $($Email.Text)</td>
</tr>
<!-- Zde bude promenna pro logiku telefonniho a mobilniho cisla -->
<tr>
<td><img src="icon_phone_2.png" alt="$AliasS"></td>
<td style="vertical-align: middle;font-family: arial; color: #000000; font-size: 12px;"> +$FullTelefonS | +$MobilS</td>
</tr>
</table>
$Global:AdresaInHTML
<table>
<tr>
<td><img src="icon_web_2.png" alt="Web"></td>
<td><img src="icon_fb_2.png" alt="Facebook"></td>
<td><img src="icon_ln_2.png" alt="Linkedin"></td>
<td><img src="icon_yt_2.png" alt="YouTube"></td>
</tr>
</table>
<span style="font-family: arial; color: #8f8f8f; font-size: 9px;">
<table>
</tr>
<td style="font-family: arial;font-size: 4px;"> </td>
</tr>
</table>
$TextPravoS
<table>
</tr>
<td style="font-family: arial;font-size: 4px;"> </td>
</tr>
</table>
$TextPravoENS
<table>
</tr>
<td style="font-family: arial;font-size: 1px;"> </td>
</tr>
</table>
</span>
</body>
</html>
"#
#-------------------------------------------------------------#
#----Control Event Handlers-----------------------------------#
#-------------------------------------------------------------#
#Write your code here
$Window = [Windows.Markup.XamlReader]::Parse($Xaml)
[xml]$xml = $Xaml
$xml.SelectNodes("//*[#Name]") | ForEach-Object { Set-Variable -Name $_.Name -Value $Window.FindName($_.Name) }
#-------------------------------------------------------------#
#----Functions------------------------------------------------#
#-------------------------------------------------------------#
# Formátuje Mobil/Pevnou linku z formátu +420XXXXXXXXX na +420 XXX XXX XXX
<#
Function Format-Contact {
param (
[String]$FormatPevnaLinka,
[String]$FormatMobil
)
if (![String]::IsNullOrWhitespace($PevnaLinka.Text)) {
$HTMLFullTelefonS = $FormatPevnaLinka.Insert(4," ").Insert(8," ").Insert(12," ")
}
if (![String]::IsNullOrWhitespace($Mobil.Text)) {
$HTMLMobilS = $FormatMobil.Insert(4," ").Insert(8," ").Insert(12," ")
}
}
#>
function CreateFolder_forSignature {
$FolderName = $Jmeno.Text +"_"+ $Prijmeni.Text
If(!(Test-path -path "\\gtxdc1.gumotex.cz\Skupiny\posta podpisy\$FolderName"))
{
New-Item -ItemType Directory -Force -Path "\\gtxdc1.gumotex.cz\Skupiny\Posta podpisy\" -Name $FolderName
}
else {
[System.Windows.MessageBox]::Show("Složka $FolderName na síťovém disku:\\gtxdc1\skupiny\posta podpisy\ již existuje, pokud chcete vytvořit znovu tuto složku prosím smažte/přejmenujte/přesuňte stávající složku.")
}
}
function CopyImages_ToNewFolder {
$FolderName = $Jmeno.Text +"_"+ $Prijmeni.Text
Copy-Item -Path "\\gtxdc1\skupiny\posta podpisy\Obrazky\*" -Destination "\\gtxdc1\skupiny\posta podpisy\$FolderName" -Recurse
}
# Functions
# Funkce pro logiku Zavodu
function CreateZavod_toHTML {
<#if ($Zavod.SelectedItem.Content -eq "PRÁZDNÉ")
{
$Global:ZavodHTML = $null
}
else {#>
$Global:ZavodHTML = #"
<tr>
<td style="font-family: arial; color: #20549A; font-weight: bold; font-size: 14px;">$($Zavod.SelectedItem.Content)</td>
</tr>
"#
}
# Funkce pro logiku Adresy
function CreateAddress_ToHTML {
$VarUlice
$VarMesto
$VarStat
switch ($Adresa.SelectedItem.Content) {
"BŘECLAV" {
$VarUlice = $Global:VarAdresaBreclavUlice
$VarMesto = $Global:VarAdresaBreclavMesto
$VarStat = $Global:VarAdresaBreclavStat
}
"TŘEBÍČ" {
$VarUlice = $Global:VarAdresaTrebicUlice
$VarMesto = $Global:VarAdresaTrebicvMesto
$VarStat = $Global:VarAdresaTrebicvStat
}
"JAROMĚŘ" {
$VarUlice = $Global:VarAdresaJaromerUlice
$VarMesto = $Global:VarAdresaJaromerMesto
$VarStat = $Global:VarAdresaJaromerStat
}
"MYJAVA" {
$VarUlice = $Global:VarAdresaMyjavaUlice
$VarMesto = $Global:VarAdresaMyjavavMesto
$VarStat = $Global:VarAdresaMyjavaStat
}
"ROŽNOV" {
$VarUlice = $Global:VarAdresaRoznovUlice
$VarMesto = $Global:VarAdresaRoznovMesto
$VarStat = $Global:VarAdresaRoznovStaT
}
}
$Global:AdresaInHTML = #"
<table>
</tr>
<td style="font-family: arial;font-size: 4px;"> </td>
</tr>
<tr>
<td style="font-family: arial; color: #717270; font-size: 11px;">$VarUlice</td>
</tr>
<tr>
<td style="font-family: arial; color: #717270; font-size: 11px;">$VarMesto</td>
</tr>
<tr>
<td style="font-family: arial; color: #717270; font-size: 11px;">$VarStat</td>
</tr>
</tr>
<td style="font-family: arial;font-size: 10px;"> </td>
</tr>
</table>
"#
}
function CreateHTMLSignature {
$FolderName = $Jmeno.Text +"_"+ $Prijmeni.Text
$FileName = $Jmeno.Text +"_"+ $Prijmeni.Text + ".html"
New-Item -ItemType File -Path "\\gtxdc1\Skupiny\Posta podpisy\$FolderName\" -Name $FileName
Set-Content -Path "\\gtxdc1\Skupiny\Posta podpisy\$FolderName\$FileName" -Value $HTML
}
$ZavritButton.Add_Click({
$Window.Close()
})
$VytvorPodpisButton.Add_Click({
CreateFolder_forSignature
CopyImages_ToNewFolder
CreateAddress_ToHTML
CreateZavod_toHTML
CreateHTMLSignature
$Window.Close()
})
#endregion
#-------------------------------------------------------------#
#----Script Execution-----------------------------------------#
#-------------------------------------------------------------#
#Format-Contact -FormatPevnaLinka $PevnaLinka.Text -FormatMobil $Mobil.Text
$Window.ShowDialog()
solution founded: At beginning of script i put this line of code:Remove-Variable * -ErrorAction SilentlyContinue Which is solved the issue

Cannot load layout in WPF application

Hello I am using windows presentation foundation and I fail to load the layout that I save but it doesnt load. I use the XmlLayoutSerializer class and the
Deserialize to load the corresponding xml fle. I assume that something is wrong with the xml file. Could you please have a look at it and check if something s wrong?
<?xml version="1.0" encoding="utf-8"?>
<LayoutRoot xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<RootPanel Orientation="Horizontal">
<LayoutAnchorablePane DockWidth="400">
<LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="Selection" IsSelected="True" ContentId="Cont1" CanClose="False" />
<LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="Settings" ContentId="Cont2" CanClose="False" />
<LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="Security settings" ContentId="Cont3" CanClose="False" />
<LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="Log" ContentId="Cont4" CanClose="False" />
</LayoutAnchorablePane>
<LayoutDocumentPane>
<LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="Project" IsSelected="True" IsLastFocusedDocument="True" ContentId="Cont5" CanClose="False" LastActivationTimeStamp="05/22/2015 14:35:39" />
<LayoutDocument Title="Layout" ContentId="Cont6" CanClose="False" />
<LayoutDocument Title="Sequences" ContentId="Cont10" CanClose="False" />
<LayoutDocument Title="Locations" ContentId="Cont11" CanClose="False" />
<LayoutDocument Title="Search" ContentId="Cont12" CanClose="False" />
<LayoutDocument Title="Task generator" ContentId="Cont13" CanClose="False" />
<LayoutDocument Title="Task manager" ContentId="Cont14" CanClose="False" />
<LayoutDocument Title="Layout validator" ContentId="Cont15" CanClose="False" />
<LayoutDocument Title="Variables" ContentId="Cont16" CanClose="False" />
</LayoutDocumentPane>
<LayoutAnchorablePane DockWidth="230">
<LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="Delta & selection tool" IsSelected="True" ContentId="Cont7" CanClose="False" />
<LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="Animations" ContentId="Cont8" CanClose="False" />
<LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="Groups" ContentId="Cont9" CanClose="False" />
<LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="Zones" ContentId="Cont10" CanClose="False" />
</LayoutAnchorablePane>
</RootPanel>
<TopSide />
<RightSide />
<LeftSide />
<BottomSide />
<FloatingWindows />
<Hidden />
</LayoutRoot>
This is the code that I use to save and load the layout (check the comments //saving layout and //loading layout).
private void RestoreWindow()
{
try
{
if (Properties.Settings.Default.WindowHeight == 0 || Properties.Settings.Default.WindowWidth == 0)
{
return;
}
}
catch(Exception e)
{
Debugger.Break();
throw;
}
Height = Properties.Settings.Default.WindowHeight;
Width = Properties.Settings.Default.WindowWidth;
Left = Properties.Settings.Default.WindowLeft;
Top = Properties.Settings.Default.WindowTop;
WindowState = (WindowState)Properties.Settings.Default.WindowState;
// loading the layout
using (var reader = new StreamReader("layoutfile.xml"))
{
XmlLayoutSerializer layoutSerializer = new XmlLayoutSerializer(DockManager);
layoutSerializer.Deserialize(reader);
}
}
private void SaveWindow()
{
Properties.Settings.Default.WindowWidth = Width;
Properties.Settings.Default.WindowHeight = Height;
Properties.Settings.Default.WindowLeft = Left;
Properties.Settings.Default.WindowTop = Top;
Properties.Settings.Default.WindowState = (int)WindowState;
// ensure that your settings are written to the disk
Properties.Settings.Default.Save();
// saving the layout
using (var writer = new StreamWriter("layoutfile.xml"))
{
XmlLayoutSerializer layoutSerializer = new XmlLayoutSerializer(DockManager);
layoutSerializer.Serialize(writer);
}
}

Implementing Drag and Swapping items in windows Phone

I am new to windows phone.My problem is the following:
I have a grid of items which are buttons. I want to implement drag and swap feature for the buttons.How to do this in WP7 platform.
Here is the solution! xaml looks like this
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<toolkit:WrapPanel Height="510" HorizontalAlignment="Left" Margin="18,56,0,0" Name="wrapPanel1" VerticalAlignment="Top" Width="411">
<Button Content="1" Height="124" Name="button2" Width="134">
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener DragDelta="GestureListener_DragDelta" DragStarted="GestureListener_DragStarted" DragCompleted="GestureListener_DragCompleted" />
</toolkit:GestureService.GestureListener>
</Button>
<Button Content="2" Height="124" Name="button3" Width="134" >
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener DragDelta="GestureListener_DragDelta" DragStarted="GestureListener_DragStarted" DragCompleted="GestureListener_DragCompleted" />
</toolkit:GestureService.GestureListener>
</Button>
<Button Content="3" Height="124" Name="button4" Width="134">
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener DragDelta="GestureListener_DragDelta" DragStarted="GestureListener_DragStarted" DragCompleted="GestureListener_DragCompleted" />
</toolkit:GestureService.GestureListener>
</Button>
<Button Content="4" Height="124" Name="button5" Width="134">
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener DragDelta="GestureListener_DragDelta" DragStarted="GestureListener_DragStarted" DragCompleted="GestureListener_DragCompleted" />
</toolkit:GestureService.GestureListener>
</Button>
<Button Content="5" Height="124" Name="button6" Width="134">
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener DragDelta="GestureListener_DragDelta" DragStarted="GestureListener_DragStarted" DragCompleted="GestureListener_DragCompleted" />
</toolkit:GestureService.GestureListener>
</Button>
<Button Content="6" Height="124" Name="button7" Width="134">
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener DragDelta="GestureListener_DragDelta" DragStarted="GestureListener_DragStarted" DragCompleted="GestureListener_DragCompleted" />
</toolkit:GestureService.GestureListener>
</Button>
<Button Content="7" Height="124" Name="button8" Width="134">
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener DragDelta="GestureListener_DragDelta" DragStarted="GestureListener_DragStarted" DragCompleted="GestureListener_DragCompleted" />
</toolkit:GestureService.GestureListener>
</Button>
<Button Content="8" Height="124" Name="button9" Width="134">
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener DragDelta="GestureListener_DragDelta" DragStarted="GestureListener_DragStarted" DragCompleted="GestureListener_DragCompleted" />
</toolkit:GestureService.GestureListener>
</Button>
<Button Content="9" Height="124" Name="button10" Width="134">
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener DragDelta="GestureListener_DragDelta" DragStarted="GestureListener_DragStarted" DragCompleted="GestureListener_DragCompleted" />
</toolkit:GestureService.GestureListener>
</Button>
<Button Content="10" Height="124" Name="button11" MouseLeftButtonDown="mouseDown" Width="134">
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener DragDelta="GestureListener_DragDelta" DragStarted="GestureListener_DragStarted" DragCompleted="GestureListener_DragCompleted" />
</toolkit:GestureService.GestureListener>
</Button>
<Button Content="11" Height="124" Name="button12" Width="134">
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener DragDelta="GestureListener_DragDelta" DragStarted="GestureListener_DragStarted" DragCompleted="GestureListener_DragCompleted" />
</toolkit:GestureService.GestureListener>
</Button>
<Button Content="12" Height="124" Name="button13" Width="134">
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener DragDelta="GestureListener_DragDelta" DragStarted="GestureListener_DragStarted" DragCompleted="GestureListener_DragCompleted" />
</toolkit:GestureService.GestureListener>
</Button>
</toolkit:WrapPanel>
</Grid>
Now the code behind C#
TranslateTransform translateTransform;
PointCollection points = new System.Windows.Media.PointCollection();
Button firstObject;
private void GestureListener_DragStarted(object sender, DragStartedGestureEventArgs e)
{
translateTransform = new TranslateTransform();
firstObject = sender as Button;
var transform1 = firstObject.TransformToVisual(wrapPanel1);
Point absolutePosition1 = transform1.Transform(new Point(0, 0));
}
private void GestureListener_DragDelta(object sender, DragDeltaGestureEventArgs e)
{
var moveablebutton = sender as Button;
moveablebutton.RenderTransform = translateTransform;
translateTransform.X += e.HorizontalChange;
translateTransform.Y += e.VerticalChange;
}
private void GestureListener_DragCompleted(object sender, DragCompletedGestureEventArgs e)
{
var lastObject = sender as Button;
Button b=new Button();
int count = wrapPanel1.Children.Count;
int index = wrapPanel1.Children.IndexOf(lastObject);
var transform2 = lastObject.TransformToVisual(wrapPanel1);
Point absolutePositon2 = transform2.Transform(new Point(0, 0));
Point P1;
Point P2 ;
Point P3 ;
Point P4 ;
P1 = e.GetPosition(wrapPanel1);
P2 = new Point(P1.X+134, P1.Y+124);
Button swapitem=null;
foreach (UIElement ctrl in wrapPanel1.Children)
{
int index2;
var transform3 = ctrl.TransformToVisual(wrapPanel1);
Point comparePos = transform3.Transform(new Point(0, 0));
swapitem = ctrl as Button;
index2 = wrapPanel1.Children.IndexOf(swapitem);
if (index != index2)
{
P3 = new Point(comparePos.X, comparePos.Y);
P4 = new Point(comparePos.X + 158, comparePos.Y+170);
if (!(P2.Y < P3.Y || P1.Y > P4.Y || P2.X < P3.X || P1.X > P4.X))
{
swapitem = ctrl as Button;
index2 = wrapPanel1.Children.IndexOf(swapitem);
b = lastObject as Button;
b.RenderTransform = translateTransform;
translateTransform.X -= e.HorizontalChange;
translateTransform.Y -= e.VerticalChange;
wrapPanel1.Children.Remove(lastObject);
wrapPanel1.Children.Remove(swapitem);
// wrapPanel1.Children.RemoveAt(index2);
if (index < index2)
{
wrapPanel1.Children.Insert(index, swapitem);
wrapPanel1.Children.Insert(index2, b);
}
else
{
wrapPanel1.Children.Insert(index2, b);
wrapPanel1.Children.Insert(index, swapitem);
}
break;
}}
}
}

Add Row Using Footers in Gridview

Ok so I am slowly making headway on my project but I am recieving the follwoing error message:
"An SqlParameter with ParameterName 'Name' is not contained by this SqlParameterCollection."
The error points to the following statement in my vb code: e.Command.Parameters("Name").Value = NewName.Text
Could someone take a look at my code and help me with what I might b doing wrong.
Here is my vb code:
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Private Sub GridView1_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles Laboratory.RowCommand
' Insert data if the CommandName == "Insert"
' and the validation controls indicate valid data...
If e.CommandName = "Insert" AndAlso Page.IsValid Then
' Insert new record...
SqlDataSource2.Insert()
End If
End Sub
Protected Sub SqlDataSource2_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles SqlDataSource2.Inserting
' Programmatically reference Web controls in the inserting interface...
Dim NewName As TextBox = Laboratory.FooterRow.FindControl("txtName")
Dim NewAddress As TextBox = Laboratory.FooterRow.FindControl("txtAddress")
Dim NewProvidence As TextBox = Laboratory.FooterRow.FindControl("txtProvidence")
Dim NewCity As TextBox = Laboratory.FooterRow.FindControl("txtCity")
Dim NewZipCode As TextBox = Laboratory.FooterRow.FindControl("txtZipCode")
Dim NewCountry As TextBox = Laboratory.FooterRow.FindControl("txtcountry")
Dim NewPhone As TextBox = Laboratory.FooterRow.FindControl("txtPhone")
Dim NewFax As TextBox = Laboratory.FooterRow.FindControl("txtFax")
Dim NewEmail As TextBox = Laboratory.FooterRow.FindControl("txtEmail")
' Set the ObjectDataSource's InsertParameters values...
' THIS IS WHERE I THINK I AM HAVING MY PROBLEM...
e.Command.Parameters("Name").Value = NewName.Text
e.Command.Parameters("Address").Value = NewAddress.Text
e.Command.Parameters("Providence").Value = NewProvidence.Text
e.Command.Parameters("City").Value = NewCity.Text
e.Command.Parameters("ZipCode").Value = NewZipCode.Text
e.Command.Parameters("Country").Value = NewCountry.Text
e.Command.Parameters("Phone").Value = NewPhone.Text
e.Command.Parameters("Fax").Value = NewFax.Text
e.Command.Parameters("Email").Value = NewEmail.Text
End Sub
And Here is my html.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<br />
<br />
<br />
<br />
<asp:GridView ID="Laboratory" runat="server" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="LaboratoryID" DataSourceID="SqlDataSource2" ShowFooter="True">
<Columns>
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" Text="Update"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
<FooterTemplate>
<asp:Button ID="AddRow" runat="server" CommandName="Insert" Text="Add" />
</FooterTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name" SortExpression="Name">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TxtName" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Address" SortExpression="Address">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Address") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtAddress" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Address") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Providence" SortExpression="Providence">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Providence") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TxtProvidence" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("Providence") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="City" SortExpression="City">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("City") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TxtCity" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("City") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ZipCode" SortExpression="ZipCode">
<EditItemTemplate>
<asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("ZipCode") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TxtZipCode" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("ZipCode") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Country" SortExpression="Country">
<EditItemTemplate>
<asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("Country") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TxtCountry" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("Country") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Phone" SortExpression="Phone">
<EditItemTemplate>
<asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("Phone") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TxtPhone" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Bind("Phone") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Fax" SortExpression="Fax">
<EditItemTemplate>
<asp:TextBox ID="TextBox8" runat="server" Text='<%# Bind("Fax") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TxtFax" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label8" runat="server" Text='<%# Bind("Fax") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Email" SortExpression="Email">
<EditItemTemplate>
<asp:TextBox ID="TextBox9" runat="server" Text='<%# Bind("Email") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TxtEmail" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label9" runat="server" Text='<%# Bind("Email") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:GreatGrizzlyConnectionString1 %>" DeleteCommand="DELETE FROM [Laboratory] WHERE [LaboratoryID] = #LaboratoryID" InsertCommand="INSERT INTO [Laboratory] ([Name], [Address], [Providence], [City], [ZipCode], [Country], [Phone], [Fax], [Email]) VALUES (#Name, #Address, #Providence, #City, #ZipCode, #Country, #Phone, #Fax, #Email)" SelectCommand="SELECT * FROM [Laboratory]" UpdateCommand="UPDATE [Laboratory] SET [Name] = #Name, [Address] = #Address, [Providence] = #Providence, [City] = #City, [ZipCode] = #ZipCode, [Country] = #Country, [Phone] = #Phone, [Fax] = #Fax, [Email] = #Email WHERE [LaboratoryID] = #LaboratoryID">
<DeleteParameters>
<asp:Parameter Name="LaboratoryID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Address" Type="String" />
<asp:Parameter Name="Providence" Type="String" />
<asp:Parameter Name="City" Type="String" />
<asp:Parameter Name="ZipCode" Type="String" />
<asp:Parameter Name="Country" Type="String" />
<asp:Parameter Name="Phone" Type="String" />
<asp:Parameter Name="Fax" Type="String" />
<asp:Parameter Name="Email" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Address" Type="String" />
<asp:Parameter Name="Providence" Type="String" />
<asp:Parameter Name="City" Type="String" />
<asp:Parameter Name="ZipCode" Type="String" />
<asp:Parameter Name="Country" Type="String" />
<asp:Parameter Name="Phone" Type="String" />
<asp:Parameter Name="Fax" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="LaboratoryID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<br />
<br />
<br />
<br />
<br />
<br />
</div>
</form>
</body>
</html>
You need to create your parameters, there are lots of variations possible but here is a simple one
Dim Name As New SqlParameter("#Name", SqlDbType.nvarchar(50))
Name.Value = txtName.text
e.Command.Parameters.Add(Name)
You would need to do this for each parameter.
If the parameter already exists then you dont need to create it! You would just use the following. All I added was the "#" to your original code.
e.Command.Parameters("#Name").Value = NewName.Text
(It has been a while since I worked on this stuff.)

Flex Mobile Project, insert multiple Image object in array

I have indexed Image, like these:
<s:Image id="imgListaTaskAnalysis0" left="20" top="110" width="200" height="200"/>
<s:Image id="imgListaTaskAnalysis1" left="20" top="360" width="200" height="200"/>
<s:Image id="imgListaTaskAnalysis2" left="20" top="360" width="200" height="200"/>
And so on..
I want to put them in an array, so:
public var arrayImg:Array = new Array(imgListaTaskAnalysis0,imgListaTaskAnalysis1,imgListaTaskAnalysis2);
But I can't give them a source:
for(var i:Number=0;i<=arrayImg.length;i++)
arrayImg[i].source = cuboImmagini.path;
In this way doesn't work, doesn't give them any source..There is a way to do this?
It is the interested part of my project:
public var arrayImg:Array = new Array(imgListaTaskAnalysis0,imgListaTaskAnalysis1);
/* DICHIARAZIONE IMMAGINI */
public var cuboImmagini:Object = {path:"../assets/cuboImmagini.png"};
public var exit:Object = {path:"../assets/exit.png"};
public var home:Object = {path:"../assets/home.png"};
/* FINE DICHIARAZIONE IMMAGINI */
/* FUNZIONI */
// cambiaPagina
public function cambiaPagina(prossimaPagina:String):void
{
currentState = prossimaPagina;
}
// chiudiApplicazione
protected function chiudiApplicazione(event:MouseEvent):void
{
NativeApplication.nativeApplication.exit();
}
public function carica():void
{
arrayImg[0].source = cuboImmagini.path;
arrayImg[1].source = home.path;
cambiaPagina("HomePage");
}
/* FINE FUNZIONI */
]]>
</fx:Script>
<s:states>
<s:State name="PaginaPresentazione"/>
<s:State name="HomePage"/>
<s:State name="ListaTaskAnalysis"/>
<s:State name="ScegliAzioneTaskAnalysis"/>
</s:states>
<fx:Declarations>
</fx:Declarations>
<!-- =================================== MXML =================================== -->
<!-- =================================== PaginaPresentazione =================================== -->
<s:Group id="gruppoPaginaPresentazione" includeIn="PaginaPresentazione" left="0" right="0" top="0" bottom="0"
horizontalCenter="0" verticalCenter="0">
<s:Button id="btnPresentazione" right="10" bottom="10" label="INIZIA"
click="carica()"/>
</s:Group>
<!-- =================================== HomePage =================================== -->
<s:Group id="gruppoHomePage" includeIn="HomePage,PaginaPresentazione" left="0" right="0" top="0"
bottom="0" horizontalCenter="0" verticalCenter="0">
<s:Button id="btnVaiTaskAnalysis" includeIn="HomePage" width="600" height="90"
label="TASK ANALYSIS" click="cambiaPagina('ListaTaskAnalysis')" fontSize="50"
horizontalCenter="0" verticalCenter="80"/>
<s:Button id="btnVaiStorieSociali" includeIn="HomePage" width="600" height="90"
label="STORIE SOCIALI" fontSize="50" horizontalCenter="0" verticalCenter="-80"/>
</s:Group>
<!-- =================================== /HomePage =================================== -->
<s:Group id="gruppoListaTaskAnalysis" includeIn="ListaTaskAnalysis" left="0" right="0" top="0" bottom="0"
horizontalCenter="0" verticalCenter="0">
<s:Group id="gruppoBottoniListaTaskAnalyis" left="0" right="0" top="0" height="90"
horizontalCenter="0">
<s:Button id="btnExitListaTaskAnalysis" right="10" top="5" width="80" height="80"
icon="assets/exit.png" click="chiudiApplicazione(event)"/>
<s:Button id="btnHomeListaTaskAnalysis" right="100" top="5" width="80" height="80"
icon="assets/home.png" click = "cambiaPagina('HomePage')"/>
</s:Group>
<s:Image id="imgListaTaskAnalysis0" left="20" top="110" width="200" height="200"
source="assets/cuboImmagini.png"/>
<s:Image id="imgListaTaskAnalysis1" left="20" top="360" width="200" height="200"/>
<s:Button id="btnSegreto1" left="10" bottom="10" width="90" height="90" alpha="0.1" click="combinazioneSegreta(1)"/>
<s:Button id="btnSegreto2" right="10" bottom="10" width="90" height="90" alpha="0.1" click="combinazioneSegreta(2)"/>
</s:Group>
<s:Group id="gruppoListaTaskAnalysis0" includeIn="ScegliAzioneTaskAnalysis" left="0" right="0"
top="0" bottom="0" horizontalCenter="0" verticalCenter="0">
<s:Group id="gruppoBottoniListaTaskAnalyis0" left="0" right="0" top="0" height="90"
horizontalCenter="0">
<s:Button id="btnExitScegliAzioneTaskAnalysis0" right="10" top="5" width="80" height="80"
icon="assets/exit.png" click="chiudiApplicazione(event)"/>
<s:Button id="btnHomeScegliAzioneTaskAnalisys" right="100" top="5" width="80" height="80"
icon="assets/home.png" click = "cambiaPagina('HomePage')"/>
</s:Group>
</s:Group>
<!-- =================================== /HomePage =================================== -->
Thanks in advance..
I solved the problem.. I put the images in the array when they are created:
<s:Image id="img" creationComplete = "loadImage(event,this.img,0) />
---------------------------------------------------------------------
public function loadImage(e:FlexEvent,img:Image,num:Number):void
{
array[num] = img;
}
Thanks anyway..

Resources