简体   繁体   中英

Easy way to do data entry in windows store app

I'm doing a simple windows 8 store app, and I would like to have a simple double click(tap) to edit.

I was thinking something along the lines of;

void editProducer(object sender, DoubleTappedRoutedEventArgs e)
{
    var t = new TextBox() {FontSize = 48, Width = 600, DataContext = DataModel.Producer};
    var f = new Flyout() {Content = t};
    f.ShowAt((FrameworkElement)sender);
}

But I have not been able to get a version of that working.

What did I miss(I've tried unsuccessfully to add binding)? Or is it totally wrong to try and do it this way?

Update;

this code almost seemed like it was going to work, and was closer to the original direction, but still didn't work;

var srcTextBlock = sender as TextBox;
var d = srcTextBlock.GetBindingExpression(TextBlock.TextProperty);
var t = new TextBlock() { FontSize = 48, Width = 200 };
t.SetBinding(TextBlock.TextProperty, d.ParentBinding);
var f = new Flyout() { Content = t };
f.ShowAt((FrameworkElement)sender);

so I eventually went with something like this for now, based on the direction suggested;

var tb = (TextBox) sender;
tb.IsReadOnly = false;
tb.SelectedText = tb.Text;
tb.LostFocus += (o, args) => { tb.IsReadOnly = true; };

A simpler way of doing this is to use a simple TextBox with a custom style which looks like a TextBlock when it is disable ( IsEnabled is false).

So then you just have to attach this event to your text fields to make it work (on double tap) :

void editProducer(object sender, DoubleTappedRoutedEventArgs e)
{
  (sender as TexBlock).IsEnabled = ! (sender as TexBlock).IsEnabled
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM