Here is my code:
settings.xaml
<TextBox x:Name="txtNumber" PreviewMouseDown="myKeyPad_PreviewMouseDown" Height="34" HorizontalAlignment="Left" Margin="-253,-123,0,0" VerticalAlignment="Top" Width="134" Background="{DynamicResource AccentColorBrush}" Controls:TextboxHelper.Watermark="Enter text here too...." />
<TextBox PreviewMouseDown="myKeyPad_PreviewMouseDown" Height="34" HorizontalAlignment="Left" Margin="-114,-123,0,0" VerticalAlignment="Top" Width="134" Background="{DynamicResource AccentColorBrush}" Controls:TextboxHelper.Watermark="Enter text here too...."/>
<TextBox x:Name="rtb1" PreviewMouseDown="myKeyPad_PreviewMouseDown" Height="34" HorizontalAlignment="Left" Margin="-253,-84,0,0" VerticalAlignment="Top" Width="134" Background="{DynamicResource AccentColorBrush}" Controls:TextboxHelper.Watermark="Enter text here too...." />
<TextBox PreviewMouseDown="myKeyBoard_PreviewMouseDown" Height="34" HorizontalAlignment="Left" Margin="-114,-83,0,0" VerticalAlignment="Top" Width="134" Background="{DynamicResource AccentColorBrush}" Controls:TextboxHelper.Watermark="Enter text here too...."/>
<StackPanel Margin="0,0,0.4,0.2">
<StackPanel Orientation="Horizontal">
<Label Content="ID:" Margin="5" Width="50"/>
<TextBox x:Name="txtId" Margin="5" Width="200"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label Content="Name:" Margin="5" Width="50"/>
<TextBox x:Name="txtName" Margin="5" Width="200"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label Content="Age:" Margin="5" Width="50"/>
<TextBox x:Name="txtAge" Margin="5" Width="200" Controls:TextboxHelper.Watermark="Enter text here too...."/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label Content="Wolle:" Margin="5" Width="50"/>
<TextBox x:Name="txtWolle" Margin="5" Width="200" Custom:TextboxHelper.Watermark="Enter Wolle here too...."/>
</StackPanel>
<Button Content="Save" x:Name="Save" Click="Save_Click" Width="100" Height="30" Margin="97,5,97.4,5"/>
</StackPanel>
</Grid>
the Setting.xaml.cs show so:
private void Save_Click(object sender, RoutedEventArgs e)
{
string id = this.txtId.Text;
string name = this.txtName.Text;
string age = this.txtAge.Text;
string Wolle = this.txtWolle.Text;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.CreateXmlDeclaration("1.0", "utf-8", "yes");
//Create a root element
XmlNode rootNode = xmlDoc.CreateElement("User");
//Create a sub element
XmlNode subNode = xmlDoc.CreateElement("User");
//Create subNode's attribute
XmlAttribute idAttribute = xmlDoc.CreateAttribute("Id");
idAttribute.Value = id;
XmlAttribute nameAttribute = xmlDoc.CreateAttribute("Name");
nameAttribute.Value = name;
XmlAttribute ageAttribute = xmlDoc.CreateAttribute("Age");
ageAttribute.Value = age;
XmlAttribute WolleAttribute = xmlDoc.CreateAttribute("Wolle");
WolleAttribute.Value = Wolle;
subNode.Attributes.Append(idAttribute);
subNode.Attributes.Append(nameAttribute);
subNode.Attributes.Append(ageAttribute);
subNode.Attributes.Append(WolleAttribute);
rootNode.AppendChild(subNode);
xmlDoc.AppendChild(rootNode);
xmlDoc.Save("User.xml");
MessageBox.Show("Created Successful");
}
how i can read the Attributes back in my TextBox on Application Start?
Related
On my Resources.xaml(Resource Dictionary) I have a DataTemplate :
<DataTemplate x:Key="ProductDetailsContentTemplate">
<StackPanel Orientation="Vertical" >
<Viewbox Margin="27,0,28,0" Height="200" >
<Image UWPUtil:ImageExtensions.CachedUriSource="{Binding ImageUri}" />
</Viewbox>
<TextBlock Text="Description" Style="{StaticResource CaptionTextBlockStyle}" FontWeight="Bold" FontSize="24"/>
<TextBlock Text="{Binding ProductDescription}" Style="{StaticResource SubtitleTextBlockStyle}" FontSize="30"/>
<TextBlock Text="Barcode" Style="{StaticResource CaptionTextBlockStyle}" FontWeight="Bold" FontSize="24"/>
<TextBlock Text="{Binding Barcode}" Style="{StaticResource SubtitleTextBlockStyle}" FontSize="30"/>
<TextBlock Text="Weight" Style="{StaticResource CaptionTextBlockStyle}" FontWeight="Bold" FontSize="24"/>
<TextBlock Text="{Binding Weight}" Style="{StaticResource SubtitleTextBlockStyle}" FontSize="30"/>
<TextBlock Text="Quantity" Style="{StaticResource CaptionTextBlockStyle}" FontWeight="Bold" FontSize="24"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="25*"/>
<ColumnDefinition Width="50*"/>
<ColumnDefinition Width="25*"/>
</Grid.ColumnDefinitions>
<Button x:Name="SubtractQytyButton" Grid.Column="0" Content="-" FontSize="24" HorizontalAlignment="Stretch"
Margin="5,0" Style="{StaticResource TestButtonStyle}" FontWeight="ExtraBold"
Click="SubQytyButton_Click"/>
<TextBox x:Name="QuantityTextBox" Grid.Column="1" HorizontalAlignment="Stretch" FontSize="24" Margin="5,0"
KeyDown="Quantity_Keydown" TextChanging="Quantity_TextChanging"
Text="{Binding Quantity, Mode=TwoWay, Converter={StaticResource DecmialConverter}}" MaxLength="5" TextAlignment="Center"/>
<Button x:Name="AddQytyButton" Grid.Column="2" Content="+" FontSize="24" HorizontalAlignment="Stretch"
Margin="5,0" Style="{StaticResource TestButtonStyle}" FontWeight="ExtraBold"
Click="AddQytyButton_Click"/>
</Grid>
</StackPanel>
</DataTemplate><br>
I file nested it using the File Nesting from Mads Kristensen , here is the thread: https://marketplace.visualstudio.com/items?itemName=MadsKristensen.FileNesting
so I have a Resources.xaml.cs on my ResourceDictionary
my problem is I want to set my QuantityTextBox Value on AddQytyButton and SubQytyButton click command, here is my click command event:
private void AddQytyButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
//does not exist in the current context
QuantityTextBox.Text = "test";
}
OR
private void AddQytyButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
Button btn = sender as Button;
// this is not working as null reference
var textbox = (btn.Parent as StackPanel).Children[1] as TextBox;
}
Thanks,
NicoTing
You should cast btn.Parent to a Grid instead of a StackPanel since you are using the former in your XAML.
var textbox = (btn.Parent as Grid).Children[1] as TextBox;
I have code to download data from WordPress
Here it is:
private async void Down_at_Start() {
RestAPI rest = new RestAPI("http://simplegames.com.ua/wp-json/wc/v1/", "ck_9d64c027d2c5f81b8bed3342eeccc6d337be813d", "cs_60697b1e6cbdeb8d62d19e0765e339f8e3334754");
WCObject wc = new WCObject(rest);
//Get all products
var orders = await wc.GetOrders();
string date = orders[0].date_created + "+0:00";
DateTime dt = DateTime.Parse(date);
string convertedDate = dt.ToString("dd/MM/yyyy HH:mm:ss");
try
{
date1.Text = convertedDate;
adress1.Text = orders[0].shipping.address_1.ToString() + " " + orders[0].shipping.address_2;
name1.Text = orders[0].billing.first_name.ToString();
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
Debug.WriteLine(e.StackTrace);
}
string date_2 = orders[1].date_created + "+0:00";
DateTime dt2 = DateTime.Parse(date_2);
string convertedDate2 = dt2.ToString("dd/MM/yyyy HH:mm:ss");
try
{
date2.Text = convertedDate2;
adress2.Text = orders[1].shipping.address_1.ToString() + " " + orders[1].shipping.address_2;
name2.Text = orders[1].billing.first_name.ToString();
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
Debug.WriteLine(e.StackTrace);
}
string date_3 = orders[2].date_created + "+0:00";
DateTime dt3 = DateTime.Parse(date_3);
string convertedDate3 = dt3.ToString("dd/MM/yyyy HH:mm:ss");
try
{
date3.Text = convertedDate3;
adress3.Text = orders[2].shipping.address_1.ToString() + " " + orders[2].shipping.address_2;
name3.Text = orders[2].billing.first_name.ToString();
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
Debug.WriteLine(e.StackTrace);
}
string date_4 = orders[3].date_created + "+0:00";
DateTime dt4 = DateTime.Parse(date_4);
string convertedDate4 = dt4.ToString("dd/MM/yyyy HH:mm:ss");
try
{
date4.Text = convertedDate4;
adress4.Text = orders[3].shipping.address_1.ToString() + " " + orders[3].shipping.address_2;
name4.Text = orders[3].billing.first_name.ToString();
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
Debug.WriteLine(e.StackTrace);
}
string date_5 = orders[4].date_created + "+0:00";
DateTime dt5 = DateTime.Parse(date_5);
string convertedDate5 = dt5.ToString("dd/MM/yyyy HH:mm:ss");
try
{
date5.Text = convertedDate5;
adress5.Text = orders[4].shipping.address_1.ToString() + " " + orders[4].shipping.address_2;
name5.Text = orders[4].billing.first_name.ToString();
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
Debug.WriteLine(e.StackTrace);
}
}
As you see I have static number of fields.
My XAML:
<Page
x:Class="Milano.InWork"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Milano"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid BorderBrush="White" BorderThickness="1">
<Grid.Background>
<ImageBrush Stretch="Fill" ImageSource="Images/Background.png"/>
</Grid.Background>
<Grid HorizontalAlignment="Left" Height="720" VerticalAlignment="Top" Width="60" BorderBrush="#FFF5F1F1" BorderThickness="0,0,1,0">
<Button x:Name="MenuButton" Content="" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Height="38" Width="38">
<Button.Background>
<ImageBrush Stretch="Uniform" ImageSource="Images/Menu-100.png"/>
</Button.Background>
</Button>
<Button x:Name="logoutbutton" Content="" HorizontalAlignment="Left" Margin="10,650,0,0" VerticalAlignment="Top" Height="43" Width="38">
<Button.Background>
<ImageBrush Stretch="Uniform" ImageSource="Images/Logout_Button.png"/>
</Button.Background>
</Button>
</Grid>
<Grid HorizontalAlignment="Left" Height="47" Margin="63,2,-121,0" VerticalAlignment="Top" Width="1338" BorderBrush="#FFFDFDFD" Padding="0,0,0,1" BorderThickness="0,0,0,1">
<TextBlock x:Name="textBlock" HorizontalAlignment="Left" TextWrapping="Wrap" Text="В Работе" VerticalAlignment="Top" Height="37" Width="1218" FontSize="32" FontFamily="SF UI Display" Padding="550,0,0,0" Foreground="White"/>
</Grid>
<ScrollViewer HorizontalAlignment="Left" Height="668" Margin="63,52,0,0" VerticalAlignment="Top" Width="350">
<StackPanel Height="1020" Width="350" BorderBrush="#FFFDFCFC" BorderThickness="0,0,1,0">
<Grid Height="204" BorderBrush="#FFFBF8F8" BorderThickness="0,0,0,1">
<TextBlock x:Name="date1" HorizontalAlignment="Left" TextAlignment="Center" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="350" Height="50" FontFamily="SF UI Display" FontSize="30" FontWeight="Light" Foreground="White" />
<TextBlock x:Name="adress1" TextAlignment="Center" HorizontalAlignment="Left" Margin="0,146,-1,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="58" Width="350" FontFamily="SF UI Display" FontSize="20" FontWeight="Light" Foreground="White" />
<TextBlock x:Name="name1" HorizontalAlignment="Left" TextAlignment="Center" Margin="0,86,-1,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="60" Width="350" FontFamily="SF UI Display" FontSize="30" FontWeight="Light" Foreground="White" Padding="0,0,0,0"/>
</Grid>
<Grid Height="204" BorderBrush="#FFFBF8F8" BorderThickness="0,0,0,1">
<TextBlock x:Name="date2" TextAlignment="Center" HorizontalAlignment="Left" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="350" Height="50" Foreground="White" FontFamily="SF UI Display" FontSize="30" FontWeight="Light" />
<TextBlock x:Name="adress2" TextAlignment="Center" HorizontalAlignment="Left" Margin="0,145,-1,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="59" Width="350" FontFamily="SF UI Display" FontSize="20" FontWeight="Light" Foreground="White" />
<TextBlock x:Name="name2" HorizontalAlignment="Left" Margin="0,87,-1,0" TextAlignment="Center" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="64" Width="350" FontFamily="SF UI Display" FontSize="30" FontWeight="Light" Foreground="White" Padding="0,0,0,50"/>
</Grid>
<Grid Height="204" BorderBrush="#FFFBF8F8" BorderThickness="0,0,0,1">
<TextBlock x:Name="date3" HorizontalAlignment="Left" TextAlignment="Center" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="350" Height="50" Foreground="White" FontFamily="SF UI Display" FontSize="30" FontWeight="Light" />
<TextBlock x:Name="adress3" HorizontalAlignment="Left" TextAlignment="Center" Margin="0,143,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="350" Height="61" FontFamily="SF UI Display" FontSize="20" FontWeight="Light" Foreground="White" />
<TextBlock x:Name="name3" HorizontalAlignment="Left" TextAlignment="Center" Margin="0,86,-1,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="60" Width="350" FontFamily="SF UI Display" FontSize="30" FontWeight="Light" Foreground="White" Padding="0,0,0,50"/>
</Grid>
<Grid Height="204" BorderBrush="#FFFBF8F8" BorderThickness="0,0,0,1">
<TextBlock x:Name="date4" HorizontalAlignment="Left" TextWrapping="Wrap" TextAlignment="Center" Text="" VerticalAlignment="Top" Width="350" Height="50" Foreground="White" FontFamily="SF UI Display" FontSize="30" FontWeight="Light" />
<TextBlock x:Name="adress4" HorizontalAlignment="Left" Margin="0,153,0,0" TextWrapping="Wrap" TextAlignment="Center" Text="TextBlock" VerticalAlignment="Top" Height="61" Width="342" FontFamily="SF UI Display" FontSize="20" FontWeight="Light" Foreground="White" />
<TextBlock x:Name="name4" HorizontalAlignment="Left" TextAlignment="Center" Margin="0,86,-1,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="60" Width="350" FontFamily="SF UI Display" FontSize="30" FontWeight="Light" Foreground="White" Padding="0,0,0,50"/>
</Grid>
<Grid Height="204" BorderBrush="#FFFBF8F8" BorderThickness="0,0,0,1">
<TextBlock x:Name="date5" HorizontalAlignment="Left" TextWrapping="Wrap" Text="" VerticalAlignment="Top" TextAlignment="Center" Width="350" Height="50" Foreground="White" FontFamily="SF UI Display" FontSize="30" FontWeight="Light" />
<TextBlock x:Name="adress5" TextAlignment="Center" HorizontalAlignment="Left" Margin="0,155,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Height="49" Width="349" FontFamily="SF UI Display" FontSize="20" FontWeight="Light" Foreground="White" />
<TextBlock x:Name="name5" HorizontalAlignment="Left" TextAlignment="Center" Margin="0,86,-1,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="60" Width="350" FontFamily="SF UI Display" FontSize="30" FontWeight="Light" Foreground="White" Padding="0,0,0,50"/>
</Grid>
</StackPanel>
</ScrollViewer>
</Grid>
How I can count how many orders in answer from website and generate grids?
Thank's for help so much! :)
I wrote function for droping list items:
private void grid1_Drop(object sender, RoutedEventArgs e)
{
TextBlock textBlock = e.Source as TextBlock;
Console.WriteLine("drop item into grid column:{0} row:{1}",
Grid.GetColumn(textBlock), Grid.GetRow(textBlock));
DataObject item = (((DragEventArgs)e).Data) as DataObject;
ListBoxItem listItem = item.GetData(typeof(ListBoxItem)) as ListBoxItem;
Window1 second = new Window1();
second.ShowDialog();
//textBlock.Height = textBlock.Height*second.getBrCasova();
Grid.SetRowSpan(textBlock, second.getBrCasova());
textBlock.Background = Brushes.Gray;
string pom = "";
if(second.getBrCasova() == 1)
textBlock.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
else
for (int i = 0; i < second.getBrCasova();i++ )
pom += "\n";
textBlock.Text = pom + listItem.Content.ToString() + "\n" + second.getUcionica();
textBlock.TextAlignment = System.Windows.TextAlignment.Center;
textBlock.Margin = new Thickness(0,0,2,2.5);
}
the problem is, if I get Grid.SetRowSpan(textBlock, second.getBrCasova()), second.getBrCasova>2, borders between cells wont be deleted.
This part of xaml show how I make table of textblocks:
<Border Grid.Column="1" Grid.Row="1" BorderBrush="Black" BorderThickness="0,0,2,2" Background="Transparent" />
<Border Grid.Column="2" Grid.Row="1" BorderBrush="Black" BorderThickness="0,0,2,2" Background="Transparent" />
<Border Grid.Column="3" Grid.Row="1" BorderBrush="Black" BorderThickness="0,0,2,2" Background="Transparent" />
<Border Grid.Column="4" Grid.Row="1" BorderBrush="Black" BorderThickness="0,0,2,2" Background="Transparent" />
<Border Grid.Column="5" Grid.Row="1" BorderBrush="Black" BorderThickness="0,0,2,2" Background="Transparent" />
<Border Grid.Column="6" Grid.Row="1" BorderBrush="Black" BorderThickness="0,0,2,2" Background="Transparent" />
<TextBlock Grid.Row="1" Grid.Column="1" Name="TextBlock11" AllowDrop="True" PreviewMouseLeftButtonDown="TextBlock11_PreviewMouseLeftButtonDown"></TextBlock>
<!--<Rectangle Grid.Column="2"
Grid.Row="1"
Stroke="Black"
Fill="Transparent" />-->
<TextBlock Grid.Row="1" Grid.Column="2" AllowDrop="True"></TextBlock>
<!--<Rectangle Grid.Column="3"
Grid.Row="1"
Stroke="Black"
Fill="Transparent" />-->
<TextBlock Grid.Row="1" Grid.Column="3" AllowDrop="True"></TextBlock>
<!--<Rectangle Grid.Column="4"
Grid.Row="1"
Stroke="Black"
Fill="Transparent" />-->
<TextBlock Grid.Row="1" Grid.Column="4" AllowDrop="True"></TextBlock>
....
How to remove this borders from function?
Thanks in advance.
Am having a Main window in my WPF application inside which am having a tabcontrol.I need to select the tabitem based on the name i pass.Each of the tabitem will contain a user control.But my problem is am not able to get the parent of the usercontrol using Parent property.Its returning null only always.Can anyone help me out.
public void selectingTab()
{
Dispatcher.BeginInvoke((Action)(() =>
{
string name = todisplayChat.GetValue<string>("FromMessenger");
string msg = todisplayChat.GetValue<string>("ChatSent");
NewChatWindow childWindow = this as NewChatWindow;
MainChatWindow parentWindow = VisualTreeHelper.GetParent(childWindow) as MainChatWindow;
//Am getting null as the value of parentWindow after the execution of this line
TabControl tabcontrolHome = parentWindow.tabcontrol_Chatwindow;
TabItem existingTab = tabcontrolHome.Items.OfType<TabItem>().SingleOrDefault(n => n.Name == name);
childWindow = (NewChatWindow)existingTab.Content;
childWindow.richtxtbox_chatwindow.AppendText(Environment.NewLine + name + " : " + msg);
}));
}
MainChatWindow.XAML
<Window x:Class="Ping.MainChatWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="600" Width="700" Icon="F:\Dhivya\C#\Personal\ChatApplication\CurrentlyWorking-Important\Ping\Ping\images\ping_logo.png" ResizeMode="CanMinimize" WindowStartupLocation="CenterScreen" WindowStyle="None" Foreground="{x:Null}" BorderBrush="#FF87A4DB" BorderThickness="2">
<Grid>
<Label Content="Ping" Height="30" HorizontalAlignment="Left" Name="lbl_Titlebar" VerticalAlignment="Top" Width="700" Background="#FF87A4DB" FontFamily="Arial" FontSize="17" Foreground="White" />
<Image Height="20" HorizontalAlignment="Left" Margin="635,5,0,0" Name="img_Minimizebutton" Stretch="Fill" VerticalAlignment="Top" Width="20" Source="F:\Dhivya\C#\Personal\ChatApplication\CurrentlyWorking-Important\Ping\Ping\images\minimize_userpage.png" />
<!--<Label Height="25" HorizontalAlignment="Left" Margin="665,5,0,0" VerticalAlignment="Top" Width="20">-->
<Image MouseEnter="close_icon_MouseEnter_1" MouseDown="close_icon_MouseDown_1" Height="20" HorizontalAlignment="Left" Margin="665,5,0,0" Name="close_icon" Stretch="Fill" VerticalAlignment="Top" Width="20" Source="F:\Dhivya\C#\Personal\ChatApplication\CurrentlyWorking-Important\Ping\Ping\images\close_userpage.png" />
<!--</Label>-->
<Label Content="Groups" Height="28" HorizontalAlignment="Left" Margin="12,46,0,0" Name="lbl_Groups" VerticalAlignment="Top" Background="#FF87A4DB" Foreground="White" BorderBrush="{x:Null}" Width="245" FontSize="16" FontFamily="Arial" />
<RichTextBox ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto" Height="175" HorizontalAlignment="Left" Margin="12,73,0,0" Name="richtxtbox_Groups" VerticalAlignment="Top" Width="245" FontFamily="Arial" />
<Label Background="#FF87A4DB" BorderBrush="{x:Null}" Content="Online Buddies" FontFamily="Arial" FontSize="16" Foreground="White" Height="28" HorizontalAlignment="Left" Margin="12,260,0,0" Name="lbl_Onlinebuddies" VerticalAlignment="Top" Width="245" />
<Grid ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto" Height="298" HorizontalAlignment="Left" Margin="12,288,0,0" Name="richtxtbox_Onlinebuddies" VerticalAlignment="Top" Width="245"></Grid>
<!--<RichTextBox ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto" Height="298" HorizontalAlignment="Left" Margin="12,288,0,0" Name="richtxtbox_Onlinebuddies" VerticalAlignment="Top" Width="245" FontFamily="Arial" />-->
<TabControl Height="540" HorizontalAlignment="Left" Margin="274,46,0,0" Name="tabcontrol_Chatwindow" VerticalAlignment="Top" Width="410">
<TabItem Header="My Profile" Name="ProfileTab">
</TabItem>
</TabControl>
</Grid>
NewChatWindow.Xaml
<UserControl x:Class="Ping.NewChatWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="540" d:DesignWidth="410">
<Grid>
<TextBox LostFocus="txt_Userinput_LostFocus_1" Foreground="Gray" GotFocus="txt_Userinput_GotFocus_1" KeyDown="txt_Userinput_KeyDown_1" Height="65" HorizontalAlignment="Left" Margin="13,161,0,0" Name="txt_Userinput" VerticalAlignment="Top" Width="378" FontFamily="Arial" Text="Enter Your Words Here" />
<RichTextBox ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto" Height="246" HorizontalAlignment="Left" Margin="13,253,0,0" Name="richtxtbox_chatwindow" VerticalAlignment="Top" Width="378" FontFamily="Arial" />
<Image Height="93" HorizontalAlignment="Left" Margin="36,36,0,0" Name="image2" Stretch="Fill" VerticalAlignment="Top" Width="65" Source="F:\Dhivya\C#\Personal\ChatApplication\CurrentlyWorking-Important\Ping\Ping\images\user_logo.png"/>
<Label Content="Label" Height="37" HorizontalAlignment="Left" Margin="124,24,0,0" Name="lbl_Username" VerticalAlignment="Top" Width="278" FontSize="24" />
<Label Content="Label" Height="28" HorizontalAlignment="Left" Margin="125,52,0,0" Name="lbl_Statusmsg" VerticalAlignment="Top" Width="284" />
<Image Height="40" Width="30" HorizontalAlignment="Left" Margin="131,89,0,0" Name="img_Profileview" Stretch="Fill" VerticalAlignment="Top" Source="F:\Dhivya\C#\Personal\ChatApplication\CurrentlyWorking-Important\Ping\Ping\images\user_logo.png" ToolTip="Add contact"/>
<Image MouseDown="img_Sendingfile_MouseDown_1" Height="40" Width="40" HorizontalAlignment="Left" Margin="191,89,0,0" Name="img_Sendingfile" Stretch="Fill" VerticalAlignment="Top" Source="F:\Dhivya\C#\Personal\ChatApplication\CurrentlyWorking-Important\Ping\Ping\images\sendingfile_icon.png" ToolTip="Fileupload"/>
<Image Height="40" Width="40" HorizontalAlignment="Left" Margin="261,89,0,0" Name="img_Videochat" Stretch="Fill" VerticalAlignment="Top" Source="F:\Dhivya\C#\Personal\ChatApplication\CurrentlyWorking-Important\Ping\Ping\images\videochat_logo.png" ToolTip="Video chat"/>
<Image MouseDown="img_Myfolder_MouseDown_1" Height="40" Width="40" Name="img_Myfolder" Stretch="Fill" Source="F:\Dhivya\C#\Personal\ChatApplication\CurrentlyWorking-Important\Ping\Ping\images\myfolder_logo.png" Margin="329,89,41,411" ToolTip="View chat history" />
<Border BorderBrush="#FF87A4DB" BorderThickness="1" HorizontalAlignment="Left" Margin="10,18,0,367" Name="border_Userdetails" Width="378" CornerRadius="2" />
</Grid>
Am having a set of labels for the online users.So when i double click any label i ll do the following
private void Label_MouseDoubleClick_1(object sender, MouseButtonEventArgs e)
{
Label selectedLabel = (Label)sender;
TabItem existingTab = tabcontrol_Chatwindow.Items.OfType<TabItem>().SingleOrDefault(n => n.Name == selectedLabel.Content);
if (tabcontrol_Chatwindow.Items.Contains(existingTab))
{
tabcontrol_Chatwindow.SelectedItem = existingTab;
}
else
{
TabItem newTab = new TabItem();
newTab.Name = selectedLabel.Content.ToString();
TabHeader header = new TabHeader();
header.userName.Content = selectedLabel.Content;
newTab.Header = header;
//newTab.Header = selectedLabel.Content;
newTab.Content = new NewChatWindow();
tabcontrol_Chatwindow.Items.Add(newTab);
tabcontrol_Chatwindow.SelectedItem = newTab;
}
}
Try using the below code, in which you can find the Window hosting your Usercontrol using Window parentWindow = Window.GetWindow(this);
Dispatcher.BeginInvoke((Action)(() =>
{
string name = todisplayChat.GetValue<string>("FromMessenger");
string msg = todisplayChat.GetValue<string>("ChatSent");
NewChatWindow childWindow = this as NewChatWindow;
MainChatWindow parentWindow = Window.GetWindow(this) as MainChatWindow;
TabControl tabcontrolHome = parentWindow.tabcontrol_Chatwindow;
TabItem existingTab = tabcontrolHome.Items.OfType<TabItem>().SingleOrDefault(n => n.Name == name);
childWindow = (NewChatWindow)existingTab.Content;
childWindow.richtxtbox_chatwindow.AppendText(Environment.NewLine + name + " : " + msg);
}));
I have a button with binding as ClearCommand which clears the value of text box but it is not working.
public SellerDetailsViewModel() //constructor
{
sdObject = new SellerDetailsTable();
_SaveCommand = new RelayCommand(Save, CanSave);
_ClearCommand = new RelayCommand(clear, Canclear);
}
private readonly ICommand _ClearCommand;
public ICommand ClearCommand { get { return _ClearCommand; } }
public event PropertyChangedEventHandler PropertyChanged;
public void onPropertyChange(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
public bool Canclear(object obj)
{
return true;
}
public void clear(object obj)
{
this.PancardNumber = "";
this.ContactNumber = 0;
this.FirstName = "";
this.LastName = "";
this.MiddleName = "";
this.OtherDocument = "";
this.Address = "";
}
<Page x:Class="CarDealer.SellerDetails"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="800" d:DesignWidth="900"
xmlns:ViewModels="clr-namespace:CarDealer.PresentationLayer.ViewModel"
Title="SellerDetails">
<Page.Resources>
<ViewModels:SellerDetailsViewModel x:Key="ViewModel">
</ViewModels:SellerDetailsViewModel>
<ControlTemplate x:Key="TextBoxErrorTemplate">
<DockPanel LastChildFill="True">
<TextBlock DockPanel.Dock="Bottom" Foreground="Red" FontSize="10pt"
Text="{Binding ElementName=MyAdorner,Path=AdornedElement.(Validation.Errors)[0].ErrorContent}"/>
<Border BorderBrush="Red" BorderThickness="2" Width="225" Height="35" >
<AdornedElementPlaceholder Name="MyAdorner" />
</Border>
</DockPanel>
</ControlTemplate>
</Page.Resources>
<Grid DataContext="{Binding Source={StaticResource ViewModel}}">
<Label Content="Seller Details" Height="39" HorizontalAlignment="Left" Margin="27,25,0,0" Name="lblTitle" VerticalAlignment="Top" FontSize="22" FontWeight="Bold" FontFamily="Times New Roman" Foreground="#FF1313D8" Width="169" />
<Label Content="First Name" Height="28" HorizontalAlignment="Left" Margin="44,87,0,0" Name="lblCustName" VerticalAlignment="Top" FontSize="16" />
<Label Content="Address" FontSize="16" Height="28" HorizontalAlignment="Left" Margin="461,253,0,0" Name="lblAdress" VerticalAlignment="Top" />
<Label Content="Pan Card Number" FontSize="16" Height="28" HorizontalAlignment="Left" Margin="44,243,0,0" Name="lblPanCardNumber" VerticalAlignment="Top" />
<Label Content="Contact Number" FontSize="16" Height="28" HorizontalAlignment="Left" Margin="44,320,0,0" Name="lblContactNumber" VerticalAlignment="Top" />
<Label Content="Handover Date" FontSize="16" Height="28" HorizontalAlignment="Left" Margin="461,170,0,0" Name="label1" VerticalAlignment="Top" />
<Label Content="Other Document" FontSize="16" Height="28" HorizontalAlignment="Left" Margin="44,399,0,0" Name="label2" VerticalAlignment="Top" />
<Button Content="Save" Height="37" Command="{Binding SaveCommand}" HorizontalAlignment="Left" Margin="299,543,0,0" Name="btnSave" VerticalAlignment="Top" Width="131" FontSize="22" />
<TextBox Height="33" Text="{Binding FirstName, Mode=TwoWay}" HorizontalAlignment="Left" Margin="205,92,0,0" Name="txtFirstName" VerticalAlignment="Top" Width="225" BorderThickness="2" FontSize="16" />
<Label Content="Last Name" FontSize="16" Height="28" HorizontalAlignment="Left" Margin="44,165,0,0" Name="label3" VerticalAlignment="Top" />
<TextBox BorderThickness="2" Text="{Binding LastName, Mode=TwoWay}" Height="33" HorizontalAlignment="Left" Margin="205,170,0,0" Name="txtLastName" VerticalAlignment="Top" Width="225" FontSize="16" />
<TextBox BorderThickness="2" Text="{Binding PancardNumber, Mode=TwoWay}" Height="33" HorizontalAlignment="Left" Margin="205,248,0,0" Name="txtPanCard" VerticalAlignment="Top" Width="225" FontSize="16" />
<TextBox BorderThickness="2" Height="33" HorizontalAlignment="Left" Margin="205,325,0,0" Validation.ErrorTemplate="{StaticResource TextBoxErrorTemplate}" Name="txtcontactNumber" VerticalAlignment="Top" Width="225" FontSize="16">
<TextBox.Text>
<Binding Path="ContactNumber">
<Binding.ValidationRules>
<ExceptionValidationRule/>
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
<TextBox Height="126" Text="{Binding Address, Mode=TwoWay}" HorizontalAlignment="Left" Margin="627,248,0,0" Name="TxtAddress" VerticalAlignment="Top" Width="257" BorderThickness="2" FontSize="16" VerticalScrollBarVisibility="Visible" />
<TextBox BorderThickness="2" Text="{Binding OtherDocument, Mode=TwoWay}" Height="126" HorizontalAlignment="Left" Margin="205,399,0,0" Name="rchTxtOtherDoc" VerticalAlignment="Top" Width="257" FontSize="16" VerticalScrollBarVisibility="Visible" />
<DatePicker Height="33" Text="{Binding HandoverDate}" HorizontalAlignment="Left" Margin="627,170,0,0" Name="dtPickerHandoverDate" VerticalAlignment="Top" Width="225" FontSize="16" />
<Button Content="Clear All" Command="{Binding ClearCommand}" FontSize="22" Height="37" HorizontalAlignment="Left" Margin="500,543,0,0" Name="btnClearAll" VerticalAlignment="Top" Width="131" />
<Label Content="Middle Name" FontSize="16" Height="28" HorizontalAlignment="Left" Margin="471,87,0,0" Name="label4" VerticalAlignment="Top" />
<TextBox BorderThickness="2" Text="{Binding MiddleName, Mode=TwoWay}" FontSize="16" Height="33" HorizontalAlignment="Left" Margin="627,87,0,0" Name="txtMiddleName" VerticalAlignment="Top" Width="225" />
</Grid>
I have debugged the code execution. clear function is executed but in the view, the textbox is not empty. Can you help me figure out what I am doing wrong?
I have added remaining code please what is missing.
You should post the rest of your xaml. Assuming your controls are TextBox's...
public void clear(object obj)
{
this.PancardNumber.Text = "";
this.ContactNumber.Text = "0"; //depends what this control is
this.FirstName.Text = "";
this.LastName.Text = "";
this.MiddleName.Text = "";
this.OtherDocument.Text = "";
this.Address.Text = "";
}
Try this, hope it helps.
public void clear(object obj)
{
this.PancardNumber = "";
this.ContactNumber = 0;
this.FirstName = "";
this.LastName = "";
this.MiddleName = "";
this.OtherDocument = "";
this.Address = "";
// should work on other document
OnPropertyChanged("OtherDocument");
}
<Button Content="Clear All" Command="{Binding ClearCommand}" FontSize="22" Height="37" HorizontalAlignment="Left" Margin="500,543,0,0" Name="btnClearAll" VerticalAlignment="Top" Width="131" />
<TextBox BorderThickness="2" Text="{Binding OtherDocument, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Height="126" HorizontalAlignment="Left" Margin="205,399,0,0" Name="rchTxtOtherDoc" VerticalAlignment="Top" Width="257" FontSize="16" VerticalScrollBarVisibility="Visible" />