在wpf中,命令无法控制边框

时间:2016-04-15 12:44:15

标签: c# wpf

我将窗口DragMove事件绑定到边框控件以移动窗口。属性是本地的:EnableDragHelper.EnableDrag =" True"你可以查看下面的设计。

           <Border Grid.Row="0" BorderThickness="1" BorderBrush="Black" Background="#467EAF" Name="borderHeader" local:EnableDragHelper.EnableDrag="True">
                <StackPanel Grid.Row="0" VerticalAlignment="Center">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"></RowDefinition>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                            <ColumnDefinition Width="*"></ColumnDefinition>
                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                            <ColumnDefinition Width="100"></ColumnDefinition>
                        </Grid.ColumnDefinitions>
                        <Label Grid.Row="0" Grid.Column="0"  HorizontalAlignment="Left" VerticalAlignment="Center" Content="{Binding InspectionHistoryModel.CurrentDateTime,Mode=TwoWay}" FontWeight="Bold" Foreground="White" FontSize="18" Margin="5,0,0,0"></Label>
                        <TextBlock Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left" Name="popupTaregetextblock" Margin="10,0,0,0" VerticalAlignment="Center">  
                        <Hyperlink FontSize="20"  Foreground="White" Command="{Binding ShowHideHeaderPopupCommand}"  CommandParameter="onDuty"><TextBlock Text="{Binding InspectionHistoryModel.HeaderDutyText, Mode=TwoWay}" VerticalAlignment="Center" FontWeight="Bold" FontSize="18" Foreground="White"> </TextBlock></Hyperlink>
                        </TextBlock>
                    </Grid>
                </StackPanel>
            </Border>

超链接的Comamnd(放入边框内)无法正常工作。怎么可能这个?拖动代码是

   private static void UIElementOnMouseMove(object sender, MouseEventArgs mouseEventArgs)
    { 
        var uiElement = sender as UIElement;
        if (uiElement != null)
        {
            if (mouseEventArgs.LeftButton == MouseButtonState.Pressed)
            {
                DependencyObject parent = uiElement;
                int avoidInfiniteLoop = 0;
                // Search up the visual tree to find the first parent window.
                while ((parent is Window) == false)
                {
                    parent = VisualTreeHelper.GetParent(parent);
                    avoidInfiniteLoop++;
                    if (avoidInfiniteLoop == 1000)
                    {
                        // Something is wrong - we could not find the parent window.
                        return;
                    }
                }
                var window = parent as Window;

                if (window.WindowState == WindowState.Maximized)
                {

                    var mouseX = mouseEventArgs.GetPosition(window).X;
                    var width = window.RestoreBounds.Width;
                    var x = mouseX - width / 2;

                    if (x < 0)
                    {
                        x = 0;
                    }
                    else
                        if (x + width > SystemParameters.PrimaryScreenWidth)
                        {
                            x = SystemParameters.PrimaryScreenWidth - width;
                        }
                    window.WindowState = WindowState.Normal;
                    window.Left = x;
                    window.Top = 0;

                //    window.Width = window.ActualWidth;
                //    window.Height = window.ActualHeight;
                //    window.Left = 0;
                //    window.Top = 0;
                //    window.WindowStartupLocation = WindowStartupLocation.Manual;
                //    window.WindowState = WindowState.Normal;

                }

                window.DragMove();
            }
        }
    }

0 个答案:

没有答案