Departure text field

I am trying to set the binding of the text of a text field inside a popup, but my setmodel parameter for the related property is never called. I have a view setup as follows:

<CommandBar>
   <AppBarButton Icon="Edit" AllowFocusOnInteraction="true">
      <Flyout>
         <StackPanel>
            <TextBlock Text="Enter Qty:" />
            <TextBox Text="{Binding EditQty, Mode=TwoWay}" InputScope="Number" />
            <Button Content="Update" Command="{Binding EditCommand}" />
         </StackPanel>
      </Flyout>
<CommandBar>

My viewmodel code is also simple:

public decimal _editQty;
public decimal EditQty
{
    get => _editQty;
    set => Set(ref _editQty, value);
}

I even tried using UpdateSourceTrigger = Explicitly with the binding, and then in the button click event, setup codebehind to call

textBox.GetBindingExpression(TextBox.TextProperty).UpdateSource();

During debugging, I see that the value of textBox.Text has changed correctly, but the installer is still not called UpdateSource (). I am using Windows 10 Build 14393 (Anniversary Edition), if that matters.

Is there any way to do this? At this point, I will have to give up the idea and place the text box in the dialog box, even if it were in the pop-up window it would be better than the user.

+4
2

Microsoft, UWP TwoWay WinRT! (: !) - float.

, , IValueConveter ( Stephan Olson, ):

public class DecimalConverter:IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, string language)
    {
        return value.ToString();
    }
    public object ConvertBack(object value, Type targetType, object parameter, string language)
    {
        return decimal.Parse(value as string);
    }
}

:

<TextBox Text="{Binding EditQty, Mode=TwoWay, Converter={StaticResource DecimalConverter}}" InputScope="Number" />
+4

/ , . . , , TextBlock DataContext:

<CommandBar>
   <AppBarButton Icon="Edit" AllowFocusOnInteraction="true">
      <Flyout>
         <StackPanel>
            <TextBlock Text="{Binding}" /> <!-- This will print typeof DataContext -->

            <TextBlock Text="Enter Qty:" />
            <TextBox Text="{Binding EditQty, Mode=TwoWay}" InputScope="Number" />
            <Button Content="Update" Command="{Binding EditCommand}" />
         </StackPanel>
      </Flyout>
<CommandBar>

TextBlock , , , DataContext Flyout.

+1

Source: https://habr.com/ru/post/1691647/


All Articles