Hi
To make a long story short, I cannot bind a textbox correctly.
This is photo of my program:
The Link[
^]
I have a tabControl. Inside the tabControl, there are several tabs that are defined by a template:
<TabControl.ContentTemplate>
<DataTemplate>
<myUserControl:UserControlTabpageContent>
</myUserControl:UserControlTabpageContent>
</DataTemplate>
</TabControl.ContentTemplate>
They contain a user control.
The tab controller is binded to a collection of this class:
[Serializable]
public class TabpageItem
{
public string Title { get; set; }
private ObservableCollection<InfoItem> infoItemCollection = new ObservableCollection<InfoItem>();
public ObservableCollection<InfoItem> InfoItemCollection
{
get { return infoItemCollection; }
}
[NonSerialized]
private ObservableCollection<InfoItem> infoItemSerachResult = new ObservableCollection<InfoItem>();
public ObservableCollection<InfoItem> InfoItemSerachResult
{
get { return infoItemSerachResult; }
}
[NonSerialized]
private string _SerachString;
public string SerachString
{
set
{
_SerachString = value;
}
get
{
return _SerachString;
}
}
}
Inside the user control I have a textbox. When the user writes something inside the textbox, the text clears by changing between tabs. If I adjust some properties, then the text does not clear but is the same for all tabs. as if all tabs are using the same data, while I like textbox of each tab operates independent.
This is WPF source of my main window:
<Window x:Class="InfoManager.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:myUserControl="clr-namespace:InfoManager.Presentation_Layer"
Title="MainWindow" Height="350" Width="507" Closed="Window_Closed">
<Grid>
<TabControl x:Name="tabControlMain" Margin="1,1,48,1" DataContext="{Binding}" Grid.RowSpan="2" Grid.ColumnSpan="2">
<TabControl.ItemTemplate>
<DataTemplate DataType="TabpageItem">
<TextBlock Text="{Binding Title}">
<TextBlock.ContextMenu>
<ContextMenu>
<MenuItem Header="Remove" Click="MenuItem_Remove_Click">
<MenuItem.Icon>
<Image Width="20" Height="20" Source="..\Resources\remove.png" Stretch="Fill" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Rename" >
<MenuItem.Icon>
<Image Height="20" Source="..\Resources\rename.png" Stretch="UniformToFill" />
</MenuItem.Icon>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Rename to: " VerticalAlignment="Center"></TextBlock>
<TextBox Text="{Binding Title}" GotMouseCapture="TextBox_GotMouseCapture"></TextBox>
</StackPanel>
</MenuItem>
</ContextMenu >
</TextBlock.ContextMenu>
</TextBlock>
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate>
<myUserControl:UserControlTabpageContent></myUserControl:UserControlTabpageContent>
</DataTemplate>
</TabControl.ContentTemplate>
<TabItem Header="tabItem1" Name="tabItem1" >
<myUserControl:UserControlTabpageContent></myUserControl:UserControlTabpageContent>
</TabItem>
</TabControl>
<Button Width="30" Height="30" HorizontalAlignment="Right" Name="buttonAddTab" VerticalAlignment="Top" Margin="0,5,5,0" Click="buttonAddTab_Click" Grid.Column="1">
<Image Source="..\resources\add.png" Stretch="UniformToFill"></Image>
</Button>
</Grid>
</Window>
and this is WPF source of my user control:
<UserControl
x:Class="InfoManager.Presentation_Layer.UserControlTabpageContent"
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="300" d:DesignWidth="300">
<Grid>
<Grid Name="grid1">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Name="grid2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Name="textBlock1" Text="Select by tags:" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10" />
<TextBox Grid.Column="1" Text="{Binding SerachString?????????????????}" Name="textBoxSelectionTags" VerticalAlignment="Center" Margin="10" />
</Grid>
<ListView Grid.Row="1" Name="listView1" Margin="10" />
</Grid>
</Grid>
</UserControl>
I put the source code here, in case it is needed:
http://www.megaupload.com/?d=S0U05X63[
^]
Thanks