UI FAQ

一. Stop ChildWindow Move.

方法1:在template里面找到Chrome (is a Border),把他的名字去掉即可。

方法2:Chrome.IsHitTestVisible = false; 可用在code-behind 取消鼠标事件响应。

方法3:使用反射的方法获取EventInfo,然后RemoveEventHandler() 注销MouseLeftButtonDown, Up, Move等事件即可。(refer http://blog.rwendi.com/HowToDynamicallyAddOrRemoveEventHandler.aspx)

由于Drag的相关事件函数是定义在ChildWindow内部的且为private,因此无法使用这种方法。

2. DragDropTarget 控件.

  1. 不能用在ChildWindow(popup型)中,主要原因可能是ChildWindow 的popup和 DragDropTarget 的popup 冲突
  2. ListBoxDragDropTarget 一定要设置AllowDrop=True, 内部的ListBox一定要设置ItemsPanel 如下:(原因不详)

    <ListBox.ItemsPanel>
              <ItemsPanelTemplate>
                        <StackPanel Orientation="Vertical"/>
               </ItemsPanelTemplate>
    </ListBox.ItemsPanel>

二、Reverse Chart Axis.

经常需要显示时间的图表。例如

image

上图为默认显示的内容,红框的Time Slot的顺序需要颠倒。

图的内容可以使用RenderTransform解决(Blend中Flip),但是Y Time Axis却不能这么办。

目前只能隐藏Axis,重新手绘了。。。(无语,源码实在太复杂了) 不知道大家有没有好的办法。

三、ScrollViewerExtensions 支持 ScrollViewer 使用鼠标滚轮

在Toolkit中提供了ScrollViewerExtensions帮助类。在XAML中为 ScrollViewer 加入toolkit:ScrollViewerExtensions.IsMouseWheelScrollingEnabled="True" 附加属性,更主要的是要设置ScrollViewer.Background="Transparent" 才能保证鼠标滚轮使用。

四、XAML不支持Project的<SupportedCultures>设置。

解决方法:

  1. 对应的UIElement的Language设置Culture名字,例如:<Grid x:Name="LayoutRoot" Language="zh-CN">
  2. 整个Silverlight的设置方法:App.Current.RootVisual.Language = XmlLanguage.GetLanguage(Thread.CurrentThread.CurrentCulture.Name);

五、TreeViewItem Style.

  1. Template中的Header [Button]的作用:Double Click => Expand or Collapse Children.
  2. SelectionStates [States Group] ,一定要参考TreeViewItem.IsSelectionActive (获取一个值,该值指示 TreeViewItem 是否具有焦点。)
    1. SelectedInactive: Selected And LostFocused
    2. Selected: Selected And GotFocused
    3. UnSelected: …

六、不要对自定义的UserControl,Control的设置Name (可能用于ElementSource Binding),每当实例化一个此控件Name都是同一Name,插入到VisualTree 会报错

七、Popup 的位置为Popup.Parent加载到VisualTree时的位置。如果Parent的位置发生更变,Popup的位置是不随更变的,例如Parent.VerticalAlign = Bottom,拖拽浏览器底边上移,Parent 位置随之上移,但Popup的位置仍然在最初的位置。解决方法:在相应的SizeChanged事件中,根据最初和现在的Parent位置调整Popup的位置

八、DataForm 不能跟踪类型为Class和集合的属性。原文:DataForm wasn’t designed to do deep change tracking on nested instances

九、UIElement.UpdateLayout() 方法 - 当自定义控件出现界面问题,比如界面消失,需要调用UpdateLayout,Silverlight将确保 UIElement 的所有子对象位置都正确地进行了布局更新,确保精确布局。

Example: 在动画Arrange(Rect) 后,界面消失,在Arrange方法前调用UpdateLayout,界面显示正常。

posted @ 2010-09-12 17:03  Silver_Throne  阅读(551)  评论(0)    收藏  举报