Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

WPF: Binding to Value of typed in string for an IsEditable ComboBox

$
0
0

I have an editable combobox box (.NET 4.0) based on a list of URL strings. The user can select from the list, or because the combobox has IsEditable=true, the user can also type in a URL. My goal is to allow the user to type in a new URL, then click a button and have the new URL saved to the list shown by the combobox dropdown.

When I type in the combobox, the UrlString that the SelectedValue is bound to becomes null. This makes sense to me since the new URL being typed in isn't part of the ListOfUrls yet.

Any ideas how to modify the code below so that when I click the btnAddUrlToList button, the Url.UrlString isn't null.

Thanks...

<Window x:Class="TestComboBox.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:TestComboBox"
        xmlns:viewModel="clr-namespace:ViewModel;assembly=ViewModel"
        Title="MainWindow" Height="350" Width="525"
        DataContext="{x:Static Member=viewModel:PreferencesViewModel.Instance}"><Grid><ComboBox Name="comboBoxUrls"
                  Height="23" Width="247" Margin="70,54,0,0" 
                  HorizontalAlignment="Left" VerticalAlignment="Top" IsEditable="True"
                  ItemsSource="{Binding Path=PreferencesContainer.Url.ListOfUrls, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
                  SelectedValue="{Binding Path=PreferencesContainer.Url.UrlString, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"/><Button Name="btnAddUrlToList" Content="Add URL to List" 
                  Height="23" Width="110" Margin="70,102,0,0" 
                  HorizontalAlignment="Left" VerticalAlignment="Top" 
                  Command="{Binding Path=GetCmdUrlAddToList}"
                  CommandParameter="{Binding Path=PreferencesContainer.Url}" />


Randy


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>