小编Dav*_*mer的帖子

如何以编程方式为WPF中的形状设置边距

边距是厚度类型所以我似乎做不到:

Double myMargin = 10.2;
ellipse1.margin = Math.Round(myMargin  / 2,0);
Run Code Online (Sandbox Code Playgroud)

那么语法是什么?

更新:左上角需要相同的保证金

wpf user-controls

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

RoutedEvent 名称已使用

在 WPF 中,我创建了 3 个用户控件“用户配置”、“系统配置”和“帐户配置”。所有这些用户控件都有“保存”和“取消”按钮。单击这些按钮后,它们会引发在各自的类中声明和定义的路由事件。单击“保存”按钮时会引发“ConfigurationSaved”事件,而单击“取消”按钮时会引发“ConfigurationCancelled”事件。

引发这些事件时,托管用户控件的容器将负责保存配置。

所有类的路由事件定义的代码片段如下:

帐户配置视图:

public partial class AccountConfigurationView : UserControl
{
    static AccountConfigurationView()
    {
        ConfigurationSavedEvent = EventManager.RegisterRoutedEvent("ConfigurationSaved",
        RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AccountConfigurationView));

        ConfigurationClosedEvent = EventManager.RegisterRoutedEvent("ConfigurationClosed",
        RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AccountConfigurationView));
    }

    #region ROUTED_EVENTS_RELATED
    public static readonly RoutedEvent ConfigurationSavedEvent;
    public static readonly RoutedEvent ConfigurationClosedEvent;

    public event RoutedEventHandler ConfigurationSaved
    {
        add { AddHandler(ConfigurationSavedEvent, value); }
        remove { RemoveHandler(ConfigurationSavedEvent, value); }
    }

    public event RoutedEventHandler ConfigurationClosed
    {
        add { AddHandler(ConfigurationClosedEvent, value); }
        remove { RemoveHandler(ConfigurationClosedEvent, value); }
    }
    #endregion
}
Run Code Online (Sandbox Code Playgroud)

系统配置视图:

public partial …
Run Code Online (Sandbox Code Playgroud)

wpf user-controls routedevent

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

WPF:从UserControl转换为CustomControl

我有一个WPF UserControl- SegmentConrol代表一行文字和一个显示方向(>)的数组.

因为我必须自定义这种控件样式,所以我决定切换到CustomControl,因为我读到这种方式更好......

现在,我有一些"麻烦"从UC切换到CC.

特别是,不知道在哪里放置<UserControl.Resources>零件.

如果任何专家可以告诉我他们受到欢迎.

这是我的UserControl:

<UserControl x:Class="MyNamespace.ctlWpfPlanDeLigne.SegmentControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             xmlns:local="clr-namespace:MyNamespace.ctlWpfPlanDeLigne"
             d:DesignHeight="300" d:DesignWidth="300"
             x:Name="ParentSegmentControl">
    <UserControl.Resources>
        <local:VisibilityConverter x:Key="VisibilityConverter"/>
        <local:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
        <local:SegmentToStringConverter x:Key="SegmentToStringConverter"/>
    </UserControl.Resources>
    <Canvas Background="Transparent">
        <Line x:Name="line"              
              X1="{Binding ElementName=ParentSegmentControl, Path=X1}"
              Y1="{Binding ElementName=ParentSegmentControl, Path=Y1}"
              X2="{Binding ElementName=ParentSegmentControl, Path=X2}"
              Y2="{Binding ElementName=ParentSegmentControl, Path=Y2}"  IsHitTestVisible="True"/>

        <Label x:Name="label" 
               Foreground="{Binding ElementName=ParentSegmentControl, Path=LabelForeground}" 
               Background="{Binding ElementName=ParentSegmentControl, Path=LabelBackground}"
               Visibility="{Binding ElementName=ParentSegmentControl, Path=IsLabelUsed, Converter={StaticResource BoolToVisibilityConverter}}"
               >
            <Label.Effect>
                <DropShadowEffect BlurRadius="2" Color="White" Opacity="1" RenderingBias="Performance" ShadowDepth="0" />
            </Label.Effect>
        </Label>
        <Polygon Name="arrow" Visibility="{Binding ElementName=ParentSegmentControl, Path=IsArrowUsed, Converter={StaticResource BoolToVisibilityConverter}}"/> …
Run Code Online (Sandbox Code Playgroud)

.net wpf user-controls wpf-controls

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

SyleProblem:无法更改特定按钮的背景?

    \n
  1. 我有一个==> UserControl
  2. \n
  3. 在 UserControl ==> One 里面ItemsControl

    \n\n

    现在按照给定的方式ItemsControl生成。\n我已经为这些按钮提供了一些样式。Button\xe2\x80\x99sItemsSource

    \n\n

    ==>按钮在里面Pages.xaml

    \n\n

    ==>和里面的样式DataPagerResourceDictionary.xaml

  4. \n
\n\n

我已经UserControl在我的Maindwindow.xaml.\n 中使用了。\n但我无法根据Button 的 ContentBackground更改特定 Button

\n\n

您可以从 这里下载完整代码。

\n\n

如果我不为按钮提供样式,下面的代码可以正常工作。

\n\n
for (int i = 0; i < displayPages.pageControl.Items.Count; i++)\n        {\n            var container = displayPages.pageControl.ItemContainerGenerator.ContainerFromIndex(i) as ContentPresenter;\n            var button = container.ContentTemplate.FindName("pageNumberButton", container) as Button;\n            if (button.Content == "  3  ")\n            {\n                button.Background …
Run Code Online (Sandbox Code Playgroud)

.net c# wpf xaml styles

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

datagrid获取单元格索引

是否有可能获取列标题="column4"并且行包含"232"的单元格索引,例如我上传的屏幕截图是否可以获得红色单元格索引而不是使其变为红色?如果wpf datagrid有这个功能,wpf工具包数据网格有吗?列和行是从代码后面添加的在此输入图像描述

c# wpf datagrid

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

使用XAML中的样式作为Shapes.Path设置MenuItem的Icon属性值

我正在使用Silverlight 4和Expression Blend 4。

我正在将MenuItem的样式设置为Icon。

<Style x:Key="1234" TargetType="Controls:MenuItem">
        <Setter Property="Header" Value="Cancel" />
        <Setter Property="Icon">
            <Setter.Value>
                <Path Fill="#FF2B2B2B"
                      Width="14.3775"
                      Height="14"
                      Canvas.Left="0.311264"
                      Canvas.Top="0.500005"
                      Stretch="Fill"
                      Data="F1 M 111.2,-85.6L 124.2,-85.6L 124.2,-72.6L 111.2,-72.6L 111.2,-85.6 Z M 117.791,-82.3439L 117.791,-80.4506L 112.685,-80.4506L 112.685,-77.8084L 117.791,-77.8084L 117.791,-75.8748L 121.025,-79.1094L 117.791,-82.3439 Z M 121.657,-84.0222L 121.657,-74.0222L 122.657,-74.0222L 122.657,-84.0222L 121.657,-84.0222 Z " />
            </Setter.Value>
        </Setter>
    </Style>
Run Code Online (Sandbox Code Playgroud)

但这在我尝试打开它时会产生异常表达式混合。

异常消息:错误HRESULT E_FAIL已从对MS.Internal.XcpImports.MethodEx(IntPtr ptr,字符串名称,CValue [] cdData)的COM组件的调用返回

当我将此样式添加到ContextMenu的项目时,这也会在运行时产生异常。

wpf xaml styles expression-blend

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

如何在没有计时器的情况下继续检查?

我需要能够连续检查鼠标是否在表单上的某个区域内.不过我希望能够在不使用计时器的情况下完成此操作.我该怎么做呢?

我正在使用C#btw.

c# user-interface mouseevent

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

是否可以识别哪个窗口/ usercontrol拥有FrameworkElement?

是否可以识别哪个窗口/用户控件拥有FrameworkElement

谢谢.

.net c# wpf frameworkelement

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

如何获取UIElement的DataContext?

由于UIElement没有财产DataContext,我怎么能得到DataContextUIElement

silverlight silverlight-4.0 uielement

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

如何在CakePHP 2.0中包含JavaScript文件

我试图包含我使用这个创建的.js文件:

echo $this->Html->script('vote');
Run Code Online (Sandbox Code Playgroud)

我的文件在/js/vote.js中

我加载网站,我转到源代码,我点击.js脚本文件,看看它是什么加载,我发现是加载vote.js是一个错误

当我尝试使用以下方法直接从URL访问时:

HTTP://本地主机:8888/mysite的/ JS/vote.js

我发现这个:


Error: JsController could not be found.
Error: Create the class JsController below in file: app/Controller/JsController.php

<?php

class JsController extends AppController {

}
Run Code Online (Sandbox Code Playgroud)

然后我创建了它所说的内容,我收到另一个错误:


Missing Method in JsController

Error: The action vote.js is not defined in controller JsController

Error: Create JsController::vote.js() in file: app/Controller/JsController.php.

<?php

class JsController extends AppController {

    public function vote.js() {

    }

}
Run Code Online (Sandbox Code Playgroud)

有什么问题?加载.JS文件为何如此复杂?

我只是想制作一个按钮来投票,我疯了......

javascript cakephp include

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