所以我可能只是稍微推动了界限......
基本上我有以下枚举,用C#代码声明:
[Flags]
public enum FlaggedEnum : int
{
Option1 = 1,
Option2 = 2,
Option3 = 4,
Option4 = 8,
...
Option16 = 32768,
None = 0
}
Run Code Online (Sandbox Code Playgroud)
此枚举是我已成功绑定到DataGrid对象的对象的成员.成功意味着我已成功绑定所有其他字段.:)
我想在这里实现的是一个控件,其中检查上面所有适当的选项,其行为和行为类似于ComboBox/ListBox.因此,您单击该字段并弹出一个下拉菜单,可以"检查"所需的任何选项.
控件还必须能够从枚举中读取并写入枚举.
我是WPF新手所以我不知道在哪里可以创建一个ComboBox并绑定到列...任何帮助将不胜感激!
我有一个看起来像这样的宏:
Foo(x) ((x - '!') & 070)
Run Code Online (Sandbox Code Playgroud)
如果我调用以下代码:
Foo('1') => 16
Run Code Online (Sandbox Code Playgroud)
但是,如果我调用以下代码:
(('1' - '!') & 70) => 0
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,这里发生了什么?为什么x & 070计算到x但x & 70计算到0?
我的猜测是左边的额外0是强制60取2个字节而不是1.在这种情况下,不会按位并且如下所示?
0000 0000 0001 0000 '16
0000 0000 0100 0110 & '70
-------------------
0000 0000 0000 0000
Run Code Online (Sandbox Code Playgroud) 我有一个TabControl每个TabItem都有一个单独的控件作为其Content元素.现在,通过使用UserControl.LoadedEventTrigger 切换到选项卡时,我可以轻松地执行故事板.但是,我还希望在从一个选项卡切换到另一个选项卡时运行退出动画(即允许旧的Content控件进行动画处理,然后是新的Content控件的入口动画).
是否可以使用标准WPF结构执行此操作?
如果没有,我将如何开发处理此问题的自定义解决方案?
编辑:
我继续做了一个修改过的TabControl,它扩展了基本的TabControl并覆盖了它的OnSelectionChanged方法,如下所示:
protected override void OnSelectionChanged(SelectionChangedEventArgs e)
{
if (e.AddedItems.Count == 1 && e.RemovedItems.Count == 1)
{
var oldTab = e.RemovedItems[0] as TabItem;
if (oldTab != null)
{
var exitStoryboard = /** code to find the storyboard **/
if (exitStoryboard != null)
{
exitStoryboard.Completed = (_, __) => base.OnSelectionChanged(e);
exitStoryboard.Begin();
return;
}
}
}
base.OnSelectionChanged(e);
}
Run Code Online (Sandbox Code Playgroud)
这很有效,除非我在选项卡之间点击太快,在这种情况下base.OnSelectionChanged永远不会被调用,大概是因为故事板不再活动了.提示?
是否可以将项目放在NSCollectionView渲染中自上而下然后左右而不是左右然后自上而下?要直观地描绘它,项目当前按以下顺序呈现:
[ 1 ] [ 2 ] [ 3 ]
[ 4 ] [ 5 ] [ 6 ]
Run Code Online (Sandbox Code Playgroud)
我希望它们看起来像这样:
[ 1 ] [ 3 ] [ 5 ]
[ 2 ] [ 4 ] [ 6 ]
Run Code Online (Sandbox Code Playgroud)
谢谢.
我有一些自定义计算,根据ScrollViewer视口的尺寸更改控件的尺寸.目前,我在获取ScrollViewer.SizeChanged事件时进行了这些计算.但是,似乎在ScrollViewer更新ViewPort维度之前执行了SizeChanged事件.我的SizeChanged事件处理程序显示ScrollViewer发件人,其Width和Height更新为新维度,但ViewportWidth和ViewportHeight属性属于旧维度.
一旦这些值发生变化,有没有办法执行代码?
我想要实现一个相对简单的事情,但我不确定如何做到。基本上,我有一个 CLR 类,如下所示:
class SomeClass
{
public SomeEnum Status;
}
public enum SomeEnum { One, Two, Three };
Run Code Online (Sandbox Code Playgroud)
我有一个 DataGrid,我ObservableCollection<SomeClass>通过后面的代码以编程方式绑定它。在此 DataGrid 中,我有一个DataGridTemplateColumn包含两个按钮,如下所示:
<toolkit:DataGridTemplateColumn Header="Actions">
<toolkit:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Button Content="ActionOne" />
<Button Content="ActionTwo" />
</StackPanel>
</DataTemplate>
</toolkit:DataGridTemplateColumn.CellTemplate>
</toolkit:DataGridTemplateColumn>
Run Code Online (Sandbox Code Playgroud)
我想要做的是将这些按钮的 IsEnabled 属性绑定到基于 {Binding Path=Status} 的值的比较。例如,在伪代码中:
ActionOne.IsEnabled = BoundValue.Status != SomeEnum.Two
ActionTwo.IsEnabled = BoundValue.Status == SomeEnum.One || BoundValue.Status == SomeEnum.Two
Run Code Online (Sandbox Code Playgroud)
无论如何,可以在 XAML 中执行此操作吗?另一种方法是为每个按钮编写一个值转换器,但由于按钮的内容和其他细节也可能有所不同,因此我不想最终编写类似 6 个值转换器的代码。
干杯!
我试图在我的应用程序中延迟加载 wintrust.dll 和 crypt32.dll (这些用于在 DLL 中执行数字签名/发布者检查)。我用的是VS2008。将这两个 DLL 添加为项目属性链接器部分的延迟加载属性中的条目后,我仍然收到 LNK4199 警告,表示未从 DLL 中加载任何内容,并且 LNK2019 错误无法解析 WinVerifyTrust 等符号。
将以下内容添加为“附加依赖项”可以缓解此问题:crypt32.lib 和 wintrust.lib。我现在没有遇到链接问题。但是,我想知道如何确保它没有链接到静态库?由于潜在的许可问题,我不想链接到静态库。我想动态加载 Windows 中安装的 DLL,并希望 DelayLoad 可以帮助我做到这一点,而不必求助于 LoadLibrary 和 GetProcAddress 函数调用。
任何有关所有不同库使用/链接选项的信息将不胜感激!
谢谢。
我觉得我可能需要一些转换器,但这就是我想要做的.我想要一个Image控件(因为它在一个绑定到实际数据的数据模板中),具有以下参数.
我的XAML代码如下.这对于精确90x90的图片(即它们不拉伸,它们使图像居中并且裁剪工作)可以正常工作.对于> 90x90的图像,裁剪工作正常但图像未居中.对于图像<90x90,图像居中但剪切似乎将图像放置在图像内容的左上区域中,因此剪辑剪辑图像的左上部分.
<Style x:Key="ImageStyle">
<Setter Property="Width" Value="90" />
<Setter Property="Height" Value="90" />
<Setter Property="Stretch" Value="None" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Clip">
<Setter.Value>
<EllipseGeometry Center="45,45" RadiusX="40" RadiusY="40" />
</Setter.Value>
</Setter>
</Style>
<Grid>
<!-- Other Stuff -->
<Image Source="{Binding ImagePath}" Style="{StaticResource ImageStyle}" />
</Grid>
Run Code Online (Sandbox Code Playgroud)
我可以通过包裹在网格中并在那里移动剪辑来摆脱第二个问题(小图像剪辑),但是大的东西不会居中:
<Grid>
<!-- Other Stuff -->
<Grid Width="90" Height="90">
<Grid.Clip>
<EllipseGeometry Center="45,45" RadiusX="40" RadiusY="40" />
</Grid.Clip>
<Image Source="{Binding ImagePath}" Style="{StaticResource ImageStyle}" />
</Grid>
</Grid>
Run Code Online (Sandbox Code Playgroud) 首先,我想指出我没有使用Mono.NET的经验,所以如果问题很愚蠢,请耐心等待.
我正在开发一个用本机C++代码编写的应用程序,适用于Windows(VS2008)和Linux/Mac(gcc).我希望集成一个库,目前在MS.NET(版本2.x)中编译.
我研究过并发现我可以使用MS提供的CCW接口调用库.因此,Windows中不应该有太多的实现问题.
我的问题是,如果我设法使用Linux或Mac中的Mono .NET编译库,我将如何从我的本机应用程序调用该代码?我想一个更简短的问题可能是,是否可以使用可以从非Windows平台上的本机C++代码调用的Mono编译器编译库?
谢谢!
我有一个关于C++析构函数行为的问题,更多的是出于好奇而不是其他任何东西.我有以下课程:
Base.h
class BaseB;
class BaseA
{
public:
virtual int MethodA(BaseB *param1) = 0;
};
class BaseB
{
};
Run Code Online (Sandbox Code Playgroud)
Imp.h
#include "Base.h"
#include <string>
class BImp;
class AImp : public BaseA
{
public:
AImp();
virtual ~AImp();
private:
AImp(const AImp&);
AImp& operator= (const AImp&);
public:
int MethodA(BaseB *param1) { return MethodA(reinterpret_cast<BImp *>(param1)); }
private:
int MethodA(BImp *param1);
};
class BImp : public BaseB
{
public:
BImp(std::string data1, std::string data2) : m_data1(data1), m_data2(data2) { }
~BImp();
std::string m_data1;
std::string m_data2;
private:
BImp(); …Run Code Online (Sandbox Code Playgroud) 我有一个奇怪的场景涉及覆盖WPF中的默认样式并将它们应用于子类.这不可能吗?例如,我有以下代码:
<Window x:Class="TestWPFStyling.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:testWpfStyling="clr-namespace:TestWPFStyling"
Title="MainWindow" Height="350" Width="525" Background="White">
<Window.Resources>
<Style TargetType="testWpfStyling:SomeLabel">
<Setter Property="Foreground" Value="Red" />
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<testWpfStyling:SomeLabel Grid.Row="0">This should be red.</testWpfStyling:SomeLabel>
<testWpfStyling:YellowLabel Grid.Row="1">This should be red.</testWpfStyling:YellowLabel>
<StackPanel Grid.Row="2">
<StackPanel.Resources>
<Style TargetType="testWpfStyling:SomeLabel">
<Setter Property="Foreground" Value="Blue" />
</Style>
</StackPanel.Resources>
<testWpfStyling:SomeLabel>This should be blue.</testWpfStyling:SomeLabel>
<testWpfStyling:YellowLabel>This should be blue.</testWpfStyling:YellowLabel>
</StackPanel>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
有了这个代码隐藏:
namespace TestWPFStyling
{
public partial class MainWindow : Window
{
}
public class SomeLabel : Label …Run Code Online (Sandbox Code Playgroud) 我的一位同事在一个内部论坛上发布了一个问题,让我思考这是否可以通过C#实现.基本上,他有一个如下界面:
public interface IProvider<T>
{
T GetT();
}
Run Code Online (Sandbox Code Playgroud)
是否可以使用实现该接口的东西作为另一个泛型类的类型参数,并且可以访问类型T而无需重新指定它?例如:
public class Foo<P> where P : IProvider<T>
{
P p;
T GetInnerT() { return p.GetT(); }
}
Run Code Online (Sandbox Code Playgroud)
这不会编译,因为类型T没有定义,因此不能用作参数IProvider.这样的事情甚至可能吗?只是好奇!
我不确定如何描述这个问题,但是这里有.我有一个在SQLite数据库中映射的对象的类层次结构.我已经编写了所有在.NET对象和数据库之间进行通信的非平凡代码.
我有一个基本界面如下:
public interface IBackendObject
{
void Read(int id);
void Refresh();
void Save();
void Delete();
}
Run Code Online (Sandbox Code Playgroud)
这是任何对象的基本CRUD操作.然后我实现了一个封装了大部分功能的基类.
public abstract class ABackendObject : IBackendObject
{
protected ABackendObject() { } // constructor used to instantiate new objects
protected ABackendObject(int id) { Read(id); } // constructor used to load object
public void Read(int id) { ... } // implemented here is the DB code
}
Run Code Online (Sandbox Code Playgroud)
现在,最后,我有了具体的子对象,每个对象在数据库中都有自己的表:
public class ChildObject : ABackendObject
{
public ChildObject() : base() { }
public ChildObject(int id) : base(id) …Run Code Online (Sandbox Code Playgroud) c# ×5
wpf ×5
c++ ×4
xaml ×3
inheritance ×2
.net ×1
ascii ×1
bitwise-and ×1
cocoa ×1
data-binding ×1
datagrid ×1
delay-load ×1
dll ×1
enums ×1
flags ×1
generics ×1
image ×1
linker ×1
linux ×1
macos ×1
mono ×1
monomac ×1
object ×1
scrollviewer ×1
storyboard ×1
tabcontrol ×1
types ×1
wpftoolkit ×1