width: expression(this.width > 50

本文介绍了一种使用CSS实现图片按比例缩放到50px*50px以内的方法,适用于网页设计中对图片尺寸控制的需求。
width: expression(this.width > 50
2007-04-17 22:17

一副大图片按比例缩小到50px*50px以内,可以参照以下这段CSS:

thumbImage {
     max-width: 50px;
     max-height: 50px;
}
* html .thumbImage {
     width: expression(this.width > 50 && this.width > this.height ? 50 : true);
     height: expresion(this.height > 50 ? 50 : true);
}

 
<basePage:BasePage x:Class="Dy.Iot.UI.Views.ToolBar.AddServicePage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation " xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml " xmlns:basePage="using:Dy.UI.Core.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008 " xmlns:local="using:Dy.Iot.UI.Views.ToolBar" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006 " xmlns:toolkit="using:Dy.Toolkit.UI.Controls" xmlns:toolkitAP="using:Dy.Toolkit.UI.AttachedProperties" Width="340" Height="360" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" mc:Ignorable="d"> <Grid Margin="20"> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <StackPanel Grid.Row="0" Orientation="Vertical"> <TextBox Width="300" Height="Auto" Margin="0,0,0,10" IsEnabled="True" Header="{x:Bind ViewModel.ServiceName, Mode=OneWay}" /> <TextBox Width="300" Height="Auto" Margin="0,0,0,10" IsEnabled="True" Header="{x:Bind ViewModel.ServiceStatus, Mode=OneWay}" /> <TextBox Width="300" Height="Auto" Margin="0,0,0,10" IsEnabled="True" Header="{x:Bind ViewModel.ServiceIpAddr, Mode=OneWay}" /> <TextBox Width="300" Height="Auto" Margin="0,0,0,10" IsEnabled="True" Header="{x:Bind ViewModel.DeviceAccessNum, Mode=OneWay}" /> </StackPanel> <Button Grid.Row="1" Width="100" Height="Auto" HorizontalAlignment="Right" VerticalAlignment="Bottom" Background="#550FF000" Content="添加服务" Command="{x:Bind ViewModel.SavedCommand}"> <Button.Style> <Style TargetType="Button"> <Setter Property="MinHeight" Value="30" /> <Setter Property="FontSize" Value="14" /> <Setter Property="FontWeight" Value="SemiBold" /> </Style> </Button.Style> </Button> </Grid> </basePage:BasePage> 这个xaml文件中TextBox 控件无法输入文字 请处理
05-21
直接改好我的代码:<Window x:Class="Zyan.MainWindow" 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:assembly="clr-namespace:System;assembly=mscorlib" xmlns:local="clr-namespace:Zyan" mc:Ignorable="d" Title="Zyan" Height="550" Width="800"> <Window.Resources> <ObjectDataProvider x:Key="keySex" MethodName="GetValues" ObjectType="{x:Type assembly:Enum}"> <ObjectDataProvider.MethodParameters> <x:Type Type="local:RowState"></x:Type> </ObjectDataProvider.MethodParameters> </ObjectDataProvider> </Window.Resources> <Grid Background="#E5E5E5"> <!-- 3 rows --> <Grid.RowDefinitions> <!-- row.0 Tool Bar --> <RowDefinition Height="Auto"/> <!-- row.1 Data View --> <RowDefinition Height="*"/> <!-- row.2 Overview --> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <!-- row.0 Tool Bar --> <TabControl Name="tab_wp" TabStripPlacement="Top" FontSize="12" Grid.Row="0"> <TabItem Name="Project" Header="Project"> <DockPanel LastChildFill="False"> <Button Name="bt_open" Content="Open" Click="chooseFile"/> <Button Name="bt_save" Content="Save"/> <Button Name="bt_save_as" Content="Save As"/> </DockPanel> </TabItem> <TabItem Name="Lib" Header="Library"> <DockPanel LastChildFill="False"> <Button Name="bt_add_lib" Content="Add"/> </DockPanel> </TabItem> <TabItem Name="Online" Header="Online"> </TabItem> <TabItem Name="Review" Header="Review"> </TabItem> <TabItem Name="Settings" Header="Settings"> </TabItem> </TabControl> <!-- row.1 Data View --> <DataGrid Name="dg_wp" Grid.Row="1" Background="White" FrozenColumnCount="1" AutoGenerateColumns="False" CanUserReorderColumns="False" CanUserSortColumns="False" CanUserAddRows="False" CanUserResizeColumns="False" ColumnWidth="*"> <!-- ==================== DataGridRow Style with ContextMenu ==================== --> <DataGrid.RowStyle> <Style TargetType="DataGridRow"> <Setter Property="Background" Value="White"/> <!-- 右键菜单 --> <Setter Property="ContextMenu"> <Setter.Value> <ContextMenu> <!-- Pending: 透明背景 --> <MenuItem Header="Pending" Command="{x:Static local:MainWindow.SetStateCommand}" CommandParameter="{x:Static local:RowState.Pending}"> <MenuItem.Style> <Style TargetType="MenuItem"> <Setter Property="Background" Value="Transparent"/> <Setter Property="Foreground" Value="Black"/> <Setter Property="Padding" Value="10,5"/> <Setter Property="FontSize" Value="12"/> </Style> </MenuItem.Style> </MenuItem> <!-- Marked: 浅黄 --> <MenuItem Header="Marked" Command="{x:Static local:MainWindow.SetStateCommand}" CommandParameter="{x:Static local:RowState.Marked}"> <MenuItem.Style> <Style TargetType="MenuItem"> <Setter Property="Background" Value="#FFF9E6"/> <Setter Property="Foreground" Value="Black"/> <Setter Property="Padding" Value="10,5"/> <Setter Property="BorderBrush" Value="#FFE599"/> <Setter Property="BorderThickness" Value="1"/> <Setter Property="FontSize" Value="12"/> </Style> </MenuItem.Style> </MenuItem> <!-- Completed: 浅蓝 --> <MenuItem Header="Completed" Command="{x:Static local:MainWindow.SetStateCommand}" CommandParameter="{x:Static local:RowState.Completed}"> <MenuItem.Style> <Style TargetType="MenuItem"> <Setter Property="Background" Value="#E6F3FF"/> <Setter Property="Foreground" Value="Black"/> <Setter Property="Padding" Value="10,5"/> <Setter Property="BorderBrush" Value="#99CFFF"/> <Setter Property="BorderThickness" Value="1"/> <Setter Property="FontSize" Value="12"/> </Style> </MenuItem.Style> </MenuItem> <!-- Rejected: 浅红 --> <MenuItem Header="Rejected" Command="{x:Static local:MainWindow.SetStateCommand}" CommandParameter="{x:Static local:RowState.Rejected}"> <MenuItem.Style> <Style TargetType="MenuItem"> <Setter Property="Background" Value="#FFE6E6"/> <Setter Property="Foreground" Value="Black"/> <Setter Property="Padding" Value="10,5"/> <Setter Property="BorderBrush" Value="#FF9999"/> <Setter Property="BorderThickness" Value="1"/> <Setter Property="FontSize" Value="12"/> </Style> </MenuItem.Style> </MenuItem> <!-- Approved: 浅绿 --> <MenuItem Header="Approved" Command="{x:Static local:MainWindow.SetStateCommand}" CommandParameter="{x:Static local:RowState.Approved}"> <MenuItem.Style> <Style TargetType="MenuItem"> <Setter Property="Background" Value="#E6FFE6"/> <Setter Property="Foreground" Value="Black"/> <Setter Property="Padding" Value="10,5"/> <Setter Property="BorderBrush" Value="#99CC99"/> <Setter Property="BorderThickness" Value="1"/> <Setter Property="FontSize" Value="12"/> </Style> </MenuItem.Style> </MenuItem> </ContextMenu> </Setter.Value> </Setter> <!-- 根据 state 设置行背景色 --> <Style.Triggers> <DataTrigger Binding="{Binding RowState}" Value="{x:Static local:RowState.Pending}"> <Setter Property="Background" Value="Transparent"/> </DataTrigger> <DataTrigger Binding="{Binding RowState}" Value="{x:Static local:StateState.Marked}"> <Setter Property="Background" Value="#FFF9E6"/> </DataTrigger> <DataTrigger Binding="{Binding RowState}" Value="{x:Static local:StateState.Completed}"> <Setter Property="Background" Value="#E6F3FF"/> </DataTrigger> <DataTrigger Binding="{Binding RowState}" Value="{x:Static local:StateState.Rejected}"> <Setter Property="Background" Value="#FFE6E6"/> </DataTrigger> <DataTrigger Binding="{Binding RowState}" Value="{x:Static local:StateState.Approved}"> <Setter Property="Background" Value="#E6FFE6"/> </DataTrigger> </Style.Triggers> </Style> </DataGrid.RowStyle> <!-- ==================== Columns ==================== --> <DataGrid.Columns> <DataGridTextColumn Header="No." Width="Auto" Binding="{Binding id, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsReadOnly="True"/> <DataGridTextColumn Header="Original" Width="*" Binding="{Binding original, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsReadOnly="True"/> <DataGridTextColumn Header="Translation" Width="*" Binding="{Binding translation, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/> </DataGrid.Columns> </DataGrid> <!-- row.2 Overview --> <Grid Name="Overview" Grid.Row="2"> </Grid> </Grid> </Window>
最新发布
12-25
根据整体,给出结果 <Window x:Class="JAFRSAO.JAFRSAO01002.Views.JAFRSAO01002View" 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:local="clr-namespace:JAFRSAO.JAFRSAO01002.Views" xmlns:behaviors="http://schemas.microsoft.com/xaml/behaviors" xmlns:lib="clr-namespace:JAFCommon.UserControls;assembly=JAFCommon" mc:Ignorable="d" Title="画面表示設定画面" Height="300" Width="400" WindowStyle="None" AllowsTransparency="True" VerticalAlignment="Top"> <Window.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="pack://application:,,,/JAFCommon;component/UserControls/Generic.xaml"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Window.Resources> <Window.InputBindings> <KeyBinding Key="F1" Command="{Binding F1Command}"/> <KeyBinding Key="F12" Command="{Binding F12Command}"/> </Window.InputBindings> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto"></RowDefinition> <RowDefinition Height="1*"></RowDefinition> <RowDefinition Height="Auto"></RowDefinition> </Grid.RowDefinitions> <!-- ヘッダー部分 --> <Grid MouseLeftButtonDown="WindowTitle_MouseLeftButtonDown"> <Border x:Name="Header" Background="{x:Static lib:JAFCommonConstants.SOLIDCOLOR_COMMON_BASE}" Height="35" VerticalAlignment="Top" Panel.ZIndex="1"> <lib:JAFCommonLabel x:Name="lblHeaderWindowTitle" Content="{Binding WindowTitle}" VerticalAlignment="Center" Margin="5,5,5,5" FontSize="{x:Static lib:JAFCommonConstants.FONT12}" FontFamily="MS Gothic" Foreground="White" Panel.ZIndex="2"/> </Border> <lib:JAFCommonButton x:Name="btnHeaderClose" Background="#FCF0FE" IsTabStop="False" Foreground="{x:Static lib:JAFCommonConstants.SOLIDCOLOR_COMMON_BASE}" FontWeight="Black" FontSize="{x:Static lib:JAFCommonConstants.FONT18}" FontFamily="{x:Static lib:JAFCommonConstants.COMMON_FONTFAMILY}" Grid.Row="0" Width="30" Height="30" Panel.ZIndex="10" HorizontalAlignment="Right" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Padding="0,2,0,0" Margin="5,0,5,0" Click="BtnHeaderCloseClick"> <TextBlock VerticalAlignment="Center">×</TextBlock> </lib:JAFCommonButton> </Grid> <Border x:Name="Footer" Background="{x:Static lib:JAFCommonConstants.SOLIDCOLOR_FOOTER_BACK}" Height="34" VerticalAlignment="Top" Panel.ZIndex="1" Margin="0,0,0,0" Grid.Row="2"> <TextBlock x:Name="FooterMessage" Text="" VerticalAlignment="Center" Margin="5,5,5,5" FontSize="{x:Static lib:JAFCommonConstants.FONT11}" FontFamily="{x:Static lib:JAFCommonConstants.COMMON_FONTFAMILY}" Foreground="{x:Static lib:JAFCommonConstants.SOLIDCOLOR_FOOTER_FORE}" Panel.ZIndex="30"/> </Border> <Rectangle Height="135" VerticalAlignment="Top" HorizontalAlignment="Center" Width="350" Margin="0,25,0,0" Stroke="#FFD1D7FF" Grid.Row="1"/> <lib:JAFCommonFooterButton x:Name="btnClose" Margin="76,0,0,10" Click="BtnCloseClick" HorizontalAlignment="Left" VerticalAlignment="Bottom" Width="100" Height="50" Grid.Row="1" Content="[F1] 閉じる"> <behaviors:Interaction.Triggers> <behaviors:EventTrigger EventName="Click"> <behaviors:CallMethodAction MethodName="BtnCloseClick" TargetObject="{Binding }" /> </behaviors:EventTrigger> </behaviors:Interaction.Triggers> </lib:JAFCommonFooterButton> <lib:JAFCommonFooterButton x:Name="btnUpdate" HorizontalAlignment="Left" Margin="224,171,0,0" Grid.Row="1" VerticalAlignment="Top" Height="50" Width="100" Content="[F12] 登録"> <behaviors:Interaction.Triggers> <behaviors:EventTrigger EventName="Click"> <behaviors:CallMethodAction MethodName="BtnUpdateClick" TargetObject="{Binding }" /> </behaviors:EventTrigger> </behaviors:Interaction.Triggers> </lib:JAFCommonFooterButton> <lib:JAFCommonLabel HorizontalContentAlignment="Center" Content="画面表示基準位置" HorizontalAlignment="Center" Margin="0,5,0,0" Grid.Row="1" VerticalAlignment="Top" Width="350" Background="#FFD1D7FF" /> <Grid x:Name="tglbtnDspPosition"> <lib:JAFCommonToggleButton x:Name="tglbtnDspPositionUp" Content="上" HorizontalAlignment="Center" Margin="0,34,0,0" Grid.Row="1" VerticalAlignment="Top" Width="148" Height="60" FontSize="16" IsChecked="{Binding IsDspPositionUp}"> <behaviors:Interaction.Triggers> <behaviors:EventTrigger EventName="ToggleClick"> <behaviors:CallMethodAction MethodName="TglbtnDspPositionClick" TargetObject="{Binding }" /> </behaviors:EventTrigger> </behaviors:Interaction.Triggers> </lib:JAFCommonToggleButton> <lib:JAFCommonToggleButton x:Name="tglbtnDspPositionDown" Content="下" HorizontalAlignment="Center" Margin="0,93,0,0" Grid.Row="1" VerticalAlignment="Top" Width="148" Height="60" FontSize="16" IsChecked="{Binding IsDspPositionDown}"> <behaviors:Interaction.Triggers> <behaviors:EventTrigger EventName="ToggleClick"> <behaviors:CallMethodAction MethodName="TglbtnDspPositionClick" TargetObject="{Binding }" /> </behaviors:EventTrigger> </behaviors:Interaction.Triggers> </lib:JAFCommonToggleButton> </Grid> </Grid> </Window>
09-26
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值