我正在寻找使用右下角的确定和取消按钮创建标准对话框/登录窗口的示例。
我不确定是否使用StackPanels,Grids或Dockpanel。我了解使用Canvas通常是不正确的,因为您必须输入x和y值。
到目前为止,我创建的是确定和取消的按钮
<StackPanel Orientation="Horizontal"
FlowDirection="RightToLeft" Height="32">
<Button Width="72" TabIndex="45" Margin="2,2,2,2">Cancel</Button>
<Button Width="72" TabIndex="40" Margin="2,2,2,2">OK</Button>
</StackPanel>
我要创建的窗口类型是标准对话框窗口。
我希望使用以下标记:
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="3*"/>
</Grid.ColumnDefinitions>
<Grid Grid.ColumnSpan="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock VerticalAlignment="Center">Username:</TextBlock>
<TextBlock VerticalAlignment="Center" Grid.Row="1">Password:</TextBlock>
<TextBox Grid.Column="1" />
<TextBox Grid.Row=1"" Grid.Column="1" />
</Grid>
<Button Grid.Row="1">Ok</Button>
<Button Grid.Row="1" Grid.Column="1">Cancel</Button>
</Grid>
是的,也可以将网格数减少到1,但是我看不出任何意义。也可以使用StackPanel代替外部Grid。
“最轻的标记”这句话可以有不同的解释。对开发人员来说最轻便是最简单明了。最轻的计算机是最快的初始化和渲染。对于给定的情况,区别实际上是在1个额外的布局容器中。确实不是要进行优化的情况
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock grid.row=1 grid.column=0 text="user name" />
<TextBlock grid.row=1 grid.column=1 text="password" />
<TextBox grid.row=2 grid.column=0 />
<TextBox grid.row=2 grid.column=1 />
<Button grid.row=3 grid.column=0 text="OK" />
<Button grid.row=3 grid.column=1 text="Cancel" />
</Grid>
对于我的应用程序,我喜欢使用ChildWindow。然后,在每个页面上,我可以验证用户是否已通过身份验证,如果不是这样,则弹出子窗口。如果您在Silverlight中使用项目的导航类型,也可以使用书签。
<toolkit:BusyIndicator IsBusy="False" Name="LoginBusy" >
<Grid x:Name="LayoutRoot" Margin="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="189*" />
<ColumnDefinition Width="189*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="65*" />
<RowDefinition Height="32" />
<RowDefinition Height="32" />
<RowDefinition Height="26*" />
<RowDefinition Height="35" />
</Grid.RowDefinitions>
<Button x:Name="OKButton" Content="OK" Click="OKButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,0,0" Grid.Row="4" Grid.Column="1" TabIndex="3" />
<sdk:Label Grid.Row="1" Name="label1" HorizontalAlignment="Right" Content="Username" Margin="4" />
<sdk:Label Grid.Row="2" Name="label2" HorizontalAlignment="Right" Content="Password" Margin="4" />
<TextBox Grid.Column="1" Grid.Row="1" Name="Username" Margin="4" Text="{Binding Username,Mode=TwoWay}" TextChanged="TextInserted" TabIndex="1" />
<PasswordBox Grid.Column="1" Grid.Row="2" Name="Password" Margin="4" Password="{Binding Password,Mode=TwoWay}" PasswordChanged="TextInserted" TabIndex="2" />
<TextBlock Grid.Column="1" Grid.Row="3" Height="37" HorizontalAlignment="Left" Visibility="Collapsed" Margin="19,13,0,0" Name="ErrorBlock" Text="Authentication Failed." VerticalAlignment="Top" Width="161" Foreground="Red" FontWeight="Bold" />
<Button Grid.Row="4" Height="23" HorizontalAlignment="Left" Margin="46,4,0,0" Visibility="Collapsed" Name="button1" Content="CANCEL" VerticalAlignment="Top" Width="75" Click="CancelButton_Click" IsTabStop="False" />
<Image Name="image1" Stretch="Fill" Source="Images/logo.png" />
</Grid>
</toolkit:BusyIndicator>
这是我的子窗口中没有标题位的内容。注意,我直接绑定到实现InotifyPropertyChanged的用户对象。同样,当Web服务执行验证时,我启用了忙碌指示器,以便用户看到他的请求正在处理中。
干杯,