Supposewe need to change the text of Label control whenever the text of TextBox control get changes or whyle typing in the TextBox in windows. For that task have to use TextChange event of TextBox in code behind . And have to write couple of code in that function.
For Example type casting of sender etc, assign the text of TextBox to Text of Label controls, the following code give an example of code bind action
Code:
TextBox TB=(Sender)TextBox;
label1.Text=TB.Text;
We could not change the text of Label Control with out using Code Behind, but WPF elemenets that problem, we can change Text of Label control without using Code Behind . Bellow code example explains how to change the text of controls when other controls text get changes.
The following code takes one TextBox and one TextBlock Control. The TextBox and TextBox's text property are binded with TextBlock controls. Here the binding property of TextBlock is used to bind Text of TextBox.
Code
<Window
x:Class="Example00.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid
>
<Grid.RowDefinitions
>
<RowDefinition
Height="*" />
<RowDefinition
Height="*" />
</Grid.RowDefinitions>
<TextBox
Name="mySourceElement"
Grid.Row="0"
Height="20"
Width="200">Hello
World</TextBox>
<TextBlock
Text="{Binding
ElementName=mySourceElement,Path=Text
}" Grid.Row="1"
Width="200" />
</Grid>
</Window>
Bhushan BandPosted Jun 30, 2015, 6:31 AM
In Detail table iwant id of Master Table
Bhushan BandPosted Jun 30, 2015, 6:24 AM
sir,Actually iam looking for Master Detail Application In Master I have TextBox and Combobox and in Detail i have Datagrid want to bind using dataset and datasource contain two tables having relation
Bhushan BandPosted Jun 30, 2015, 6:08 AM
<Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <Border HorizontalAlignment="Stretch" Margin="11" VerticalAlignment="Center" BorderThickness="2" CornerRadius="20"> <TextBlock Text="" VerticalAlignment="Center" FontSize="18" FontWeight="Bold" Margin="7,0" /> </Border> <!--<StackPanel Grid.Row="1" HorizontalAlignment="Left" Margin="11" VerticalAlignment="Top" Width="432" Orientation="Horizontal" DataContext="{StaticResource CustomerViewSource}"> <TextBlock Text="Select Customer" HorizontalAlignment="Left" VerticalAlignment="Center" /> <ComboBox HorizontalAlignment="Left" VerticalAlignment="Center" Width="175" Margin="7,0" DisplayMemberPath="Name" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding}" SelectedIndex="0" SelectedValuePath="CustomerID" /> </StackPanel>--> <Grid x:Name="Requisition" DataContext="{StaticResource CustomerViewSource}" Grid.Row="2" Margin="11" VerticalAlignment="Top"> <Grid.ColumnDefinitions> <ColumnDefinition Width="157*"/> <ColumnDefinition Width="585*"/> </Grid.ColumnDefinitions> <TextBox x:Name="RecCode" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" Margin="10,21,0,0" Text="{Binding RecCode}" Grid.ColumnSpan="2"/> <TextBox x:Name="RequisitionNo" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" Margin="35,28,0,0" Text="{Binding RequisitionNo}"/> <DatePicker x:Name="RequisitionDate" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="69.851,28,0,0" Text="{Binding RequisitionDate}" Grid.Column="1"/> <ComboBox x:Name="SiteCode" HorizontalAlignment="Left" VerticalAlignment="Top" Width="278" Margin="215.851,32,0,0" DisplayMemberPath="TheName" SelectedValuePath="RecCode" SelectedValue="{Binding SiteCode}" ItemsSource="{Binding}" Grid.Column="1" /> </Grid> <Grid Grid.Row="3" DataContext="{StaticResource CustomerAddressesViewSource}"> <DataGrid AutoGenerateColumns="False" EnableRowVirtualization="True" IsSynchronizedWithCurrentItem="True" Margin="11" Name="AddressesDataGrid" AlternatingRowBackground="#FFE1E1E1" HorizontalGridLinesBrush="Gray" VerticalGridLinesBrush="Gray" ItemsSource="{Binding}"> <DataGrid.Columns> <DataGridTextColumn Header="SrNo" Width="220" Binding="{Binding SrNo}" > <DataGridTextColumn.ElementStyle> <Style TargetType="TextBlock"> <Setter Property="TextWrapping" Value="Wrap"/> </Style> </DataGridTextColumn.ElementStyle> <DataGridTextColumn.EditingElementStyle> <Style TargetType="TextBox"> <Setter Property="Foreground" Value="Blue"/> </Style> </DataGridTextColumn.EditingElementStyle> </DataGridTextColumn> <DataGridComboBoxColumn Width="100" x:Name="ItemCode" Header="Items" SelectedValueBinding="{Binding ItemCode, Mode=TwoWay}" ItemsSource="{Binding}" DisplayMemberPath="TheName" SelectedValuePath="RecCode" /> <DataGridTextColumn Header="Quantity" Width="220" Binding="{Binding Quantity}"> <DataGridTextColumn.ElementStyle> <Style TargetType="TextBlock"> <Setter Property="TextWrapping" Value="Wrap"/> </Style> </DataGridTextColumn.ElementStyle> <DataGridTextColumn.EditingElementStyle> <Style TargetType="TextBox"> <Setter Property="Foreground" Value="Blue"/> </Style> </DataGridTextColumn.EditingElementStyle> </DataGridTextColumn> <!--<DataGridTextColumn Header="Parent" Width="220" Binding="{Binding ParentCode}"> <DataGridTextColumn.ElementStyle> <Style TargetType="TextBlock"> <Setter Property="TextWrapping" Value="Wrap"/> </Style> </DataGridTextColumn.ElementStyle> <DataGridTextColumn.EditingElementStyle> <Style TargetType="TextBox"> <Setter Property="Foreground" Value="Blue"/> </Style> </DataGridTextColumn.EditingElementStyle> </DataGridTextColumn>--> <!--<DataGridTemplateColumn Header="Parent"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <ItemsControl> <ItemsControl.ItemTemplate> <DataTemplate> <TextBlock> <TextBlock.Style> <Style TargetType="TextBlock"> <Setter Property="Text" Value="{x:Null}" /> <Style.Triggers> <DataTrigger Binding="{Binding ParentCode}" Value="True"> <Setter Property="Text" Value="{Binding ElementName=RecCode, Path=Text,Mode=TwoWay}" /> </DataTrigger> </Style.Triggers> </Style> </TextBlock.Style> </TextBlock> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn>--> <!--DataGridTemplateColumn Header="ParentCode"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock> <TextBox Text="{Binding Text,ElementName="RecCode",Mode=TwoWay}" Width="200"/> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn>--> <DataGridTextColumn x:Name="ParentCode" Header="Parent" Binding="{Binding FK_DetRequisitionDetails/RecCode}"/> <!--<DataGridTextColumn Header="Parent" Binding="{Binding ElementName= RecCode,Path=Text,Mode=TwoWay}" ></DataGridTextColumn>--> <!--x:Name="ParentCode" x:Uid="ParentCode" <DataGridTextColumn x:Name="ParentCode" Header="Parent" Binding="{Binding ElementName=RecCode, Path=Text,Mode=TwoWay }" ></DataGridTextColumn>--> <!--<DataGridTextColumn x:Name="ParentCode" Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}, AncestorLevel=2}, Path=RecCode}" ></DataGridTextColumn>--> <!--<DataGridCheckBoxColumn Header="MVP" Width="50" Binding="{Binding IsMVP}" IsThreeState="True" /> <DataGridTemplateColumn Header="DOB"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock Text="{Binding DOB}" Margin="4"/> </DataTemplate> </DataGridTemplateColumn.CellTemplate> <DataGridTemplateColumn.CellEditingTemplate> <DataTemplate> <DatePicker SelectedDate="{Binding DOB, Mode=TwoWay}" /> </DataTemplate> </DataGridTemplateColumn.CellEditingTemplate> </DataGridTemplateColumn>--> </DataGrid.Columns> </DataGrid> </Grid> <Button Content="Change Row Color" Height="23" HorizontalAlignment="Left" Margin="12,277,0,0" Name="RowColorButton" VerticalAlignment="Top" Width="116" Click="RowColorButton_Click" /> </Grid>
Former memberPosted Jun 30, 2015, 6:01 AM
please share full xaml code, so that i can give solution
Bhushan BandPosted Jun 30, 2015, 2:50 AM
I get text in Datagrid Textbox from other element but i want to bind these value to datatable column
Bhushan BandPosted Jun 29, 2015, 4:06 PM
Plz help me its very urgent
Bhushan BandPosted Jun 29, 2015, 4:04 PM
Get all the values from datagrid to datatable but parentcode column shows null
Bhushan BandPosted Jun 29, 2015, 4:00 PM
Want text of reccode element bind to parentcode so that i can save value of parentcode plz help me
Bhushan BandPosted Jun 29, 2015, 3:57 PM
for ex:<DataGridTextColumn Header="Parent" Binding="{Binding ParentCode, ElementName= RecCode,Path=Text,Mode=TwoWay}" ></DataGridTextColumn> is it possible it gives error
Former memberPosted Jun 29, 2015, 9:57 AM
first i would like to say, textblock does not allow to enter text.if you change text using code behind then in this example it will not change the text of textbox, but if you mention binding mode to two way then the text box text will be changed
Bhushan BandPosted Jun 29, 2015, 8:02 AM
if i want to insert value of Textblock using binding then whats the procedure