小编cod*_*oop的帖子

如何让一组切换按钮像WPF中的单选按钮一样?

我有一组按钮,它们应该像切换按钮一样,但也可以作为单选按钮,在当前时间只能选择/按下一个按钮.它还需要具有不选择/按下任何按钮的状态.

行为将有点像Photoshop工具栏,其中零或一个工具随时被选中!

知道如何在WPF中实现这一点吗?

wpf

117
推荐指数
4
解决办法
7万
查看次数

在WPF TextBox中粘贴事件

我创建了一个自定义控件继承TextBox.此自定义控件是数字TextBox,仅支持数字.

OnPreviewTextInput用来检查每个键入的新字符,看看该字符是否是有效的输入.这非常有效.但是,如果我将文本粘贴到TextBox,OnPreviewTextInput则不会被触发.

捕获粘贴文本的最佳方法是TextBox什么?

此外,我在按下后退空间时遇到问题,我无法弄清楚这将触发什么事件.OnPreviewTextInput没被解雇!

有关如何在WPF中捕获粘贴文本和后台空间事件的任何想法TextBox

c# wpf events textbox

61
推荐指数
3
解决办法
4万
查看次数

为每个角设置一个具有不同画笔颜色的边框

我已经创建了一个静态资源来定义我的xaml中特定项的边框,但我找不到为每个边定义唯一颜色的好方法!

XAML:

<Border Style="{StaticResource SidePanelBorder}">
        <!-- rest of the xaml -->
</Border>
Run Code Online (Sandbox Code Playgroud)

静态资源:

<Style x:Key="SidePanelBorder">
    <Setter Property="Control.BorderBrush" Value="#FF363636" />
    <Setter Property="Control.BorderThickness" Value="1" />
</Style>
Run Code Online (Sandbox Code Playgroud)

但是我想为边框的每一边定义一种颜色,最后还要有不同的边框厚度.

有没有什么好的技术呢?

wpf xaml border colors

34
推荐指数
3
解决办法
7万
查看次数

使用StaticResource SolidColorBrush定义渐变停止颜色

我正在创建一些包含应用程序所有样式的wpf资源字典!我有一些LinearGradientBrushes,其中颜色直接在L inearGradientBrush参考中设置为GradientStops.但是,我希望有一组预定义的颜色,我可以为每个颜色使用一个引用GradientStop,这样更改应用程序的颜色方案就是更改SolidColorBrushes 的值:

<SolidColorBrush Color="#5A5A5A" x:Key="colorbrushMedium" /> 
<SolidColorBrush Color="#222222" x:Key="colorbrushDark" />  


<LinearGradientBrush>
    <GradientStop Color="{StaticResource colorbrushMedium}"/>
    <GradientStop Color="{StaticResource colorbrushDark}" Offset="1"/>
</LinearGradientBrush>
Run Code Online (Sandbox Code Playgroud)

使用上面的代码示例,我收到以下错误:

Cannot convert the value in attribute 'Color' to object of type 'System.Windows.Media.Color'. '#5A5A5A' is not a valid value for property 'Color'.  
Run Code Online (Sandbox Code Playgroud)

它引用的行<GradientStop Color="{StaticResource colorbrushMedium}"/>是定义的行.

有任何想法吗?

wpf resources xaml colors brushes

29
推荐指数
2
解决办法
3万
查看次数

WPF:按下enter按钮时在搜索字段中执行命令绑定

我的WPF应用程序中有一个搜索字段,其中包含一个包含命令绑定的搜索按钮.这很好用,但是当按下键盘上的Enter键时,如何对文本字段使用相同的命令绑定?我见过的例子都是使用KeyDown事件处理程序后面的代码.有没有一种聪明的方法可以使用xaml和命令绑定来完成这项工作?

c# wpf xaml commandbinding

21
推荐指数
2
解决办法
1万
查看次数

当使用ItemsControl ItemsControl.ItemsPanel设置为Canvas时,ContenPresenter进入并破坏了我在[WPF]上的Canvas属性

我正在使用ItemsControl,其中ItemsPanel设置为Canvas(有关更多背景信息,请参阅问题).ItemsControl正在按我的意愿执行,当通过将子元素放入ItemsControl.Items手动添加子元素时,它就像一个魅力:

<ItemsControl>
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <Canvas IsItemsHost="True" />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.Items>
        <Button Canvas.Left="500" Content="Button Text" />
    </ItemsControl.Items>
</ItemsControl>
Run Code Online (Sandbox Code Playgroud)

注意Button上的Canvas.Left属性.这就像魅力一样,Button位于ItemsControl左侧500像素的位置.大!

但是,当我定义与List的ItemsSource绑定时,Canvas.left没有任何影响:

<ItemsControl ItemsSource="{Binding Elements}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <Canvas IsItemsHost="True" />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Button Canvas.Left="500" Content="Button Text" />
        </DataTemplate>     
    </ItemsControl.ItemTemplate>
</ItemsControl> 
Run Code Online (Sandbox Code Playgroud)

通过在运行时检查应用程序,我看到了一个区别.在Canvas和按钮之间添加了容器ContentPresenter.

如何在ContentPresenter本身上设置Canvas.Left属性?或者有另一种方法可以解决这个问题吗?

谢谢大家!

wpf canvas itemscontrol

16
推荐指数
2
解决办法
9279
查看次数

WPF滚动视图滚动到底部默认值

我有一个ScrollViewer包含ListBox.我希望ScrollViewer在加载视图时默认滚动到底部!这是因为最近的元素始终是最后一个元素ListBox.

有没有一种简单的方法来实现这种行为?

谢谢

wpf listbox scrollviewer

11
推荐指数
1
解决办法
1万
查看次数

通过js添加类不会触发css动画

我有一个修改版本animate.css(添加了一些延迟,新的时间和新的位置),默认情况下设置类(html文档)时,它的工作非常好.但是当我通过js动态添加动画类时,动画不会被执行!

更令人烦恼的是,我确实让它在某些时候工作,但我无法让它再次工作(使用gumby框架和inview js在元素在屏幕上时添加一个类(添加.animated)).左侧框已经在html中有类,右侧框有js添加的.animate类.

示例:http:
//onepageframework.com/28_2_14/strange_anim.html

任何想法为什么右框不动画?

使用Gumby inview扩展:http://gumbyframework.com/docs/extensions/#!/inview

编辑:添加html:

<div class="six columns text-center fadeInLeftMedium delay_2 animated">
    <!-- left box content here -->
</div>
<div class="six columns text-center fadeInLeftMedium delay_2 inview" data-classname="animated">
    <!-- right box content here -->
</div>
Run Code Online (Sandbox Code Playgroud)

CSS:

.animated {
    -webkit-animation-duration: 1s;
       -moz-animation-duration: 1s;
         -o-animation-duration: 1s;
            animation-duration: 1s;
    -webkit-animation-fill-mode: both;
       -moz-animation-fill-mode: both;
         -o-animation-fill-mode: both;
            animation-fill-mode: both;
}

.delay_2 {
    -webkit-animation-delay: 2s;
       -moz-animation-delay: 2s;
         -o-animation-delay: 2s;
            animation-delay: 2s;    
}

@-webkit-keyframes fadeInLeftMedium {
    0% { …
Run Code Online (Sandbox Code Playgroud)

html5 css3 css-animations web gumby-framework

9
推荐指数
2
解决办法
9343
查看次数

无边框窗口应用程序比屏幕分辨率占用更多空间

我在WPF中创建了一个无边界应用程序,它运行得很好.但是,当我将WindowState设置为全屏时,应用程序会占用比屏幕分辨率更多的空间,因此屏幕外的所有方向都有一些像素!(看起来添加了一些硬编码的负边距来隐藏默认边框)

任何想法如何防止这种情况发生?

我的xaml:

<Window x:Class="MyApp.Shell"
    WindowStyle="None"
    BorderThickness="0"
    AllowsTransparency="True"
    Background="Transparent"
    ResizeMode="CanResizeWithGrip"
    WindowState="{Binding MainApplicationWindowState}"
    ...
Run Code Online (Sandbox Code Playgroud)

另外,我看到的另一个问题是Windows工具栏/任务栏被覆盖在fullsize状态,因此它看起来像是使用"实际"屏幕高度而不是"可用"屏幕高度,这意味着屏幕高度减去窗口工具栏/任务栏!

有人找到了这些问题的解决方案吗?

谢谢

wpf window fullscreen borderless

8
推荐指数
2
解决办法
7710
查看次数

WPF,让verticalstretch按预期工作!

我试图使垂直拉伸按预期工作在WPF中,但由于某种原因它只需要它所需的空间,而不是可用的空间.

首先,我使用的是带有C#和Prism的WPF.

在Shell.xaml(应用程序的主要xaml)中,我有一个包含2列和一行的网格.我们的想法是拥有一个侧面板和一个主应用区域.主应用程序区域网格设置为"自动宽度"和"自动高度".这是按预期工作的,并且它可以缩放以适应整个应用程序的高度和宽度.

然后我使用prism将视图(作为UserControl组件)插入主应用程序区域.UserControl也设置为自动宽度和高度,通过查看Expression Blend中的默认设置,Horizo​​ntalAlignment和VerticalAlignment设置为拉伸!

但是,装载了棱镜的UserControl只能以宽度拉伸而不是高度!通过为背景颜色提供视觉反馈,我可以看到它只需要根据需要的垂直空间,而不是整个区域可用!

这可能是什么解决方案?我试过通过所有设置手动覆盖它们到宽度和高度自动,水平和垂直对齐拉伸,但似乎没有任何工作按预期!

一些代码:(Shell.xaml)

<Window Height="1140" Width="1450">
    <Grid Margin="0" Background="White">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="250" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid Background="#FFEEEEEE" Grid.Column="0" Grid.Row="0">   
            </Grid>          
            <ItemsControl Width="Auto" Height="Auto" Grid.Row="0" Grid.Column="1" Name="MainRegion" cal:RegionManager.RegionName="MainRegion" Padding="10" Margin="10, 0, 0, 0" Background="#FFFFFFD5" />
        </Grid>
    </Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)

(视图应该继承父高度):

<UserControl Width="Auto" Height="Auto" Background="Red" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
     <!-- I want this to take the full width and height of the parent -->
</UserControl>
Run Code Online (Sandbox Code Playgroud)

那么这是视图加载到主xaml中的方式的限制,还是这是UserControl限制,还是我不理解的其他内容?

只是为了澄清; 我确实看到Shell.xaml中定义的ItemsControl的背景颜色同时拉伸水平和垂直,但不是加载到ItemsControl中的视图的背景.

请注意,我删除了一些xaml,以便更容易理解!

谢谢!

wpf xaml prism

7
推荐指数
2
解决办法
2834
查看次数