I had an textbox in which user can enter text and there was an list box below the text box which shows the collections of objects of a class. When user selects any one of the list box item i am displaying the list box item in the textbox using the text property in the selected event of the list box. Now my concern here is i want to make the selected list box item as hyperlink in textbox which is clickable same as like in message composer in windows phone. And user can continue typing the text in the textbox after item was selected to select the next list box item. Can any one help me to find the solution.
yea its clear now. Can you checkthis link 'http://www.jayway.com/2011/10/05/wp7-link-in-text-with-richtextbox-on-mango/'
Hope this will help you. You can try this way.
<TextBlock x:Name="tbref" Visibility="Collapsed"/>
<RichTextBox >
<RichTextBox.Template>
<ControlTemplate>
<StackPanel Orientation="Horizontal">
<HyperlinkButton x:Name="txtnam" Content="{Binding Text,ElementName=tbref}" HorizontalAlignment="Left" VerticalAlignment="Center" />
<TextBox Width="200"/>
</StackPanel>
</ControlTemplate>
</RichTextBox.Template>
</RichTextBox>
selection event handler
private void lst_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
{
var selectedString = lst.SelectedItem;
tbref.Text = selectedString.ToString();
}
Related
I would like to know a way to make some text appear when you press a button.
I've already created a button and a text box:
<Button Height="25" Width="200" Click="Button_Click" Content="Press this button"/>
<TextBlock Height="50" Width="300" Margin="243,147,249,222" TextAlignment="Center" FontSize="30"/>
Also, I've created a boolean for when you press the button, I donĀ“t know if this is necessary or not.
private void Button_Click(object sender, RoutedEventArgs e)
{
Boolean button = true;
}
Basically, like MaxB said, every control in WPF has a "Visibility" property, that you can change between Visible, Collapsed or Hidden.
Since you already have a Handle for the Button_Click event, all you need to do now is give a name to your TextBlock with the x:Name property like-so :
<TextBlock x:Name="MyTextBlock"/>
Then, in the code of your handler, you can choose which Visibility to apply to the TextBlock according to the state of your boolean.
You can access the TextBlock properties by the name you gave it in the XAML file, like-so :
this.MyTextBlock.Visibility = Visibility.Hidden, for example.
You didn't create a textbox you created a textblock. Firstly create a textbox and give it a name. Then on your Button_click method you can write NameOfTextBox.Text = "Your text";
i have a combo box where user can type input and it will display the corresponding values based on the selection, but if user type any character like "C" by default it was displaying the first matching word "CAR" and the relevant data in other fields.
if user changes the input data was not clearing in other fields.
if user types values other then the values existing in the drop down still it shows the values that are previously populated and it was not clearing at all.
i want to autocomplete the combo box based on user input so that user can select from the drop down and if user types any value which are not in the drop down all the auto populated need to be cleared.
From your question I understand like you can use lostfocus event on Text Property rather than SelectedItem
<ComboBox KeyUp="cmbDevice_KeyUp" IsEditable="True" x:Name="cmbDevice" TextSearchEnabled="True" Text="{Binding SelectedDevice,UpdateSourceTrigger=LostFocus}" ItemsSource="{Binding DeviceList }">
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel />
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>
private void cmbDevice_KeyUp(object sender, KeyEventArgs e)
{
cmbDevice.IsDropDownOpen = true;
}
By making the below changes in the xaml it works fine
TextSearch.Text="{Binding usertext}" Text="{Binding ticketText}" IsEnabled="{Binding IsTicketEnable}" ItemsSource="{Binding LstTicket}" DisplayMemberPath="ticket" ValuePath="ticket" SelectedItem="{Binding SelectedTicket}" TextChanged="cmbTicket_TextChanged"SelectedItemChanged="cmbTicket_SelectedItemChanged"
I have a ComboBox as specified below:
<ComboBox Height="31" Margin="7,7,0,0" Name="callerID" IsEditable="True" Background="LightBlue" KeyDown="callerIDbar_KeyDown" Foreground="White" FontSize="17" FontWeight="Bold" HorizontalContentAlignment="Center" VerticalAlignment="Top" Grid.Row="0" Grid.Column="0" />
storedCalls is a collection of phone numbers that will be populated to the ComboBox.Items:
foreach (string call in storedCalls)
{
if (call != "Enter a number to dial")
callerID.Items.Add(call);
}
All this works fine. I populate the Items primary because I like the autocomplete that is driven by the values in the ComboBox's Items collections. Is there a way the XAML to disable the drop down error, and disable the drop down menu? I.e. make a simple auto complete textbox like control?
I have seen full on TextBox controls that include a bunch of code-behind and complicated markup, and this is not what I am looking to do. I just need to disable the ability of the drop down menu from showing.
You can handle the DropDownOpened event and then close it.
So in n the XAML you get:
<ComboBox x:Name="cb" DropDownOpened="cb_DropDownOpened"/>
And in Code Behind:
private void cbCategoria_DropDownOpened(object sender, EventArgs e)
{
ComboBox cb = sender as ComboBox;
cb.IsDropDownOpen = false;
}
I prefear this solution reather than set MaxDropDownHeight to 0.
Your choice.
I am building an app for Windows Phone, and in this app I have a list of Movies with Title, Plot and Picture.
I have this list bound to a ListBox with a custom DataTemplate for the items showing the data. I also created a second page to show the details of each movie.
My problem now is the navigation between these pages. I'm using MVVM to build the applications and most of the approaches I've found searching on internet is to use the OnSelectionChanged event in the code-behind, but it goes agains what I want, that is to use MVVM.
Other approach I've seen, which is the one I'm trying, is to bind the SelectedItem to a property in the ViewModel, but I can't make it change the property, it seems that I cannot select an item in the listbox. Also, I don't have the visual feedback when I press one of the items in my listbox, like the feedback we have in the settings menu of the phone for example.
The code I'm using in the listbox is:
<ListBox Margin="0,0,-12,0" ItemsSource="{Binding Movies}" SelectedItem="{Binding SelectedMovieItem}" SelectionMode="Single" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,0,0,17">
<!--Replace rectangle with image-->
<Rectangle Height="50" Width="50" Fill="#FFE5001b" Margin="12,0,9,0"/>
<StackPanel Width="311">
<TextBlock Text="{Binding Name}" TextWrapping="NoWrap" Style="{StaticResource PhoneTextExtraLargeStyle}" Foreground="#000" />
<!--<TextBlock Text="{Binding LineTwo}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>-->
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Another approach I've seen is to use the INavigationService to achieve this, I found this article: http://windowsphonegeek.com/articles/MVVM-in-real-life-Windows-Phone-applications-Part1
I read the parts one and two, but I couldn't understand this one works.
So, what I want to know is whether the approach I'm using is the correct to make a page navigation, or if there is a better way using MVVM to do this with visual feedback on the listbox.
Why is handling Event in the code behind against MVVM? Handling events interaction is part of the UI. Of course you won't all you code logic there. But you are trying just to go to the next page. I do something like this :
private void MainListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// If selected index is -1 (no selection) do nothing
if (MainListBox.SelectedIndex == -1)
return;
// Navigate to the new page
NavigationService.Navigate(new Uri("/Views/detailsPage.xaml?selectedItem=" + MainListBox.SelectedIndex, UriKind.Relative));
// Reset selected index to -1 (no selection)
MainListBox.SelectedIndex = -1;
}
Hello friends i want to display data from DB to combobox, DB table has id, investPlan, amount. Now i want to show 'investPln' col in combobox and when user selects any plan then respective amount displays in textBox control. I am able to display 'invetsPlan' rows in comboBox but don't know how to do rest thing. HELP ME!!
XAML Part
<ComboBox Height="23" Margin="70,72,88,0" Name="comboBox1" VerticalAlignment="Top" DropDownClosed="comboBox1_DropDownClosed"
ItemsSource="{Binding}" IsSynchronizedWithCurrentItem="True" SelectedValue="{Binding Path=id}" DisplayMemberPath="fullName" SelectedValuePath="id"/>
Code Behind Part
private void Window_Loaded(object sender, RoutedEventArgs e)
{
DataSet1TableAdapters.membersTableAdapter ta = new ComboBoxDB.DataSet1TableAdapters.membersTableAdapter();
comboBox1.ItemsSource = ta.GetData();
}
You're almost there!
<TextBox Text="{Binding ElementName=comboBox1, Path=SelectedItem.amount}" />
There you go :)
Combobox has a event to fire on change of an item .You can use that .SelectionChanged event