开发者

ChildWindow causes my DataForm to gray out

If I popup a child window in my editable dataform it will gray out until you click on it again. Is this a bug?

<UserControl x:Class="DataFormChild.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:dataFormToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm.Toolkit"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">

<Grid x:Name="LayoutRoot" Background="White">
    <dataFormToolkit:DataForm AutoEdit="True" ItemsSource="{Binding}" >
        <StackPanel>
        <dataFormToolkit:DataField>                
                <TextBox Text="{Binding Age, Mode=TwoWay}" />                
        </dataFormToolkit:DataField>
        <Button Content="LaunchPopup" Click="Button_Click"/>
        </StackPa开发者_如何转开发nel>
    </dataFormToolkit:DataForm>
</Grid>

namespace DataFormChild
{
   public partial class MainPage : UserControl
   {

      DataItem _data = new DataItem() { Age = 1 };
      public MainPage ()
      {

         InitializeComponent();

         ObservableCollection<DataItem> list = new ObservableCollection<DataItem>();
         list.Add( _data );
         this.DataContext = list;
      }

      private void Button_Click ( object sender, RoutedEventArgs e )
      {
         ChildWindow1 cwnd = new ChildWindow1();
         cwnd.Show();
      }
   }

   public class DataItem : IEditableObject
   {
      public int Age { get; set; }
      public void BeginEdit () { }
      public void CancelEdit () { }
      public void EndEdit () { }

   }

}


This is by design.

The focus is on the child window and the user should be entering data on that, reading the error message, or what ever is presented there. This is so important that the user can't do anything else.

Once the action is complete and the child window dismissed then control is returned to the main window.

If you don't want this behaviour then you should look at other mechanisms for getting the user to input data.


As ChrisF said its by design but if you don't want that behavior then you can change the control template for ChildWindow and remove the darkening behavior.

You need to modify the Overlay control in the ChildWindow template


What's happening is that showing the ChildWindow is causing the form to commit. This takes it out of Edit Mode and into Read Only mode, and hence the controls are greyed out.

When you click on the form again, because you have got AutoEdit set to true, you start editing the data again, and its no longer grey.

The easiest way to resolve this is to add AutoCommit="False" to your DataForm.


I have this same issue on a SL3 app but it has nothing to do with the form committing. I know this because all my controls including the dataform "OK" and "Cancel" are still visible and enabled, just gray. It stays gray when I set focus on any of the controls, but when I change a textbox value everything returns to normal. This only occurs when a dataform is the parent, if the main app is the parent then everything is fine.


If you look at the source, ChildWindow will IsEnabled = false on the application's rootvisual. This causes a visual state transition on the dataform which overlays an element across the dataform. Upon leaving the disabled state, the element is not removed (Opacity set back to 0). If you do not need the disabled state visual, the simplest fix is to edit a copy of the default template and remove the Disabled state DoubleAnimation which causes the "DisabledVisual" to show.


I just had the same problem and resolved it by taking the Buttons out of the Data Form

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜