我在应用游戏中获得了2个面板
它们都受到不同元素的束缚.
GameDetailsPanel.DataContext = game ;
GameBoardPanel.DataContext = gameBoard ;
Run Code Online (Sandbox Code Playgroud)
*游戏有Turn Property*.
public Class Game
{
public bool Turn{ get; set;}
}
Run Code Online (Sandbox Code Playgroud)
现在我需要将GameBoardPanel中的一个绑定到Property Turn的值,
*例如:类似*的东西
<Button Fill={Binding Source=GameDetailsPanel.DataContext , Path=Turn } ></Button>
Run Code Online (Sandbox Code Playgroud)
我如何在绑定中引用GameDetailsPanel.DataContext?
我有几个项目控件,只有在满足某个条件时才需要为其PreviewMouseLeftButtonDown事件附加一个事件处理程序.
我用一个数据触发器为我的控件设计了一个样式,我检查了它的绑定并尝试使用BorderThickness属性的常规属性设置器来查看数据触发器的工作原理.(确实......)
当使用事件设置器以与常规属性设置器相同的方式满足datatrigger的条件时,如何应用我的datatrigger来附加事件处理程序?
类似的东西:
<Style TargetType="{x:Type ItemsControl}">
<Style.Triggers>
<DataTrigger Binding="{Binding Turn}" Value="True">
<EventSetter Event="PreviewMouseLeftButtonDown" Handler="ItemsControl_MouseLeftButtonDown"></EventSetter>
</DataTrigger>
</Style.Triggers>
</Style>
Run Code Online (Sandbox Code Playgroud)
此标记在eventsetter行上抛出以下异常:
'Set property 'System.Windows.EventSetter.Event' threw an exception.'
Run Code Online (Sandbox Code Playgroud)
内在例外:
{"Value cannot be null.\r\nParameter name: value"}
Run Code Online (Sandbox Code Playgroud) 我需要在ListBoxItems中的项目之间加入一个分隔符,例如,我的项目源中的某些项目将放置在分隔符下方,而某些项目位于分隔符下方.
例如 :
以上是通过更改ListBox的ControlTemplate来完成的:
<ScrollViewer>
<StackPanel>
<ItemsPresenter />
<Separator BorderBrush="Red" />
<ListBoxItem Content=".." ContentTemplate="..." x:Key="helpItem"/>
</StackPanel>
</ScrollViewer>
Run Code Online (Sandbox Code Playgroud)
问题是"helpItem"没有被选中,因为它不是我的ItemsSource的一部分.
现在可以选择它就足够了
1)所以我的第一个问题是如何将这个项目与我的ItemsSource相关联,或者让它可以选择?
未来还有更多,我可能不会有更多的项目放在我的列表框的下半部分
2)我如何将分隔符放置在我的项目之间的给定位置,就像将我的ItemsPresenter划分为逻辑位置一样?
我似乎无法弄清楚为什么我不能添加对.net命名空间的引用System.Linq.我使用aspnet_regiis来检查我是否安装了最新版本的asp.net:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319>aspnet_regiis -lv
2.0.50727.0 C:\Windows\Microsoft.NET\Framework64\v2.0.50727\aspnet_isapi.dll
4.0.30319.0 C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll
4.0.30319.0 C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll
Run Code Online (Sandbox Code Playgroud)
我也试过添加一个引用System.Core,但我仍然无法引用该System.LinqDLL.
也在我的web.config下
<assemblies>
<add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
Run Code Online (Sandbox Code Playgroud)
正如我在网站应用程序中对System.Core和System.Data.Linq的引用之前所提到的:在属性页面 - >引用我可以清楚地看到现有的参考我再次添加它们以防万一仍然我不能使用System.Linq或System.Linq.Data NameSpaces.
任何想法如何我可以参考System.Linq DLL将不胜感激.
我遇到了一个面试问题,我不知道答案(小帮助:))它说的有点类似:
Class SomeClass : IDisposable
{
public void Dispose()
{
while(true)
{
}
}
~SomeClass()
{
Dispose();
}
}
Run Code Online (Sandbox Code Playgroud)
1)在下一个GC之后不再引用时,对象是否已完成?我的答案是否定的,因为终结线程将停留在无限循环上.
2)在Dispose中可以做什么来结束最终化以及在对象被处置之前循环继续多少次(没有考虑它将在下一代中花费的时间)
我不是特别清楚确切的问题(2).我有点没时间了......
不知道答案我把一个静态计数器变为3并调用break并声明3在技术上会起作用:),但那不是答案
我猜它与GC.SupressFinalize()有关吗?也许在进入循环之前调用GC.SupressFinalize()?
任何想法,如果不是对不明确的问题的答案,更多的是他们可能的目标是什么?
我的Xml文件:
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfCustomer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Customer>
<CustomerId>1f323c97-2015-4a3d-9956-a93115c272ea</CustomerId>
<FirstName>Aria</FirstName>
<LastName>Stark</LastName>
<DOB>1999-01-01T00:00:00</DOB>
</Customer>
<Customer>
<CustomerId>c9c326c2-1e27-440b-9b25-c79b1d9c80ed</CustomerId>
<FirstName>John</FirstName>
<LastName>Snow</LastName>
<DOB>1983-01-01T00:00:00</DOB>
</Customer>
</ArrayOfCustomer>
Run Code Online (Sandbox Code Playgroud)
我的尝试:
XElement toEdit =
(XElement)doc.Descendants("ArrayOfCustomer")
.Descendants("Customer")
.Where(x => Guid.Parse((x.Descendants("CustomerId") as XElement).Value) == customer.CustomerId)
.First<XElement>();
Run Code Online (Sandbox Code Playgroud)
这会引发以下异常:
Object reference not set to an instance of an object.
Run Code Online (Sandbox Code Playgroud)
1)不是x一个XElement?
2)这是一个适合选择Xml节点的lambda吗?
3)当然你会如何找到这个节点CustomerId?
我正在尝试创建一个源自的自定义控件ItemsControl.将ItemsControl被初始化的项目,但他们没有显示.
itemsControl:
public class PipeControl : ItemsControl
{
static PipeControl()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(PipeControl), new FrameworkPropertyMetadata(typeof(PipeControl)));
}
public PipeControl()
{
Checkers = new ObservableCollection<Checker>();
Checkers.Add(new Checker());
Checkers.Add(new Checker());
Checkers.Add(new Checker());
Checkers.Add(new Checker());
Checkers.Add(new Checker());
}
public ObservableCollection<Checker> Checkers
{
get;
set;
}
}
Run Code Online (Sandbox Code Playgroud)
主题资源字典:Generic.xaml
<Style TargetType="{x:Type local:PipeControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:PipeControl}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate DataType="{x:Type local:Checker}">
<Ellipse Fill="Red" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
</DataTemplate>
</Setter.Value>
</Setter> …Run Code Online (Sandbox Code Playgroud) 我有2个项目项目A,项目B,项目A有项目B的参考,项目A是可执行项目.
Project A --> Project B
Run Code Online (Sandbox Code Playgroud)
在项目B内部有一个名为"MyFolder"的目录
所以灵魂运动的层次结构如下:
MySolution
- A
- B
- MyFolder
Run Code Online (Sandbox Code Playgroud)
如何从项目A(可执行文件)中获取MyFolder的相对路径.
我找到了大量答案,其中说明了以下内容:
sring path = Assembly.GetAssembly(typeof(SomeClassInBProject)).Location;
Run Code Online (Sandbox Code Playgroud)
我从这里回来的路径是A的bin\debug中B.dll的路径,我如何在该.dll中检索路径.
编辑:
我也尝试过:
Assembly assembly = Assembly.GetAssembly(typeof(SomeClassInBProject));
FileStream fs = assembly.GetFile(@"MyFolder\myFile");
and
FileStream fs = assembly.GetFile("MyFolder\myFile");
and
FileStream fs = assembly.GetFile("myFile");
Run Code Online (Sandbox Code Playgroud)
fs我总是空的.
我需要创建一个圆形ProgressBar模板.
ControlTemplate:
<ControlTemplate TargetType="{x:Type ProgressBar}">
<Grid x:Name="TemplateRoot" SnapsToDevicePixels="true">
<Rectangle x:Name="PART_Track" Margin="1" Fill="White" />
<Border x:Name="PART_Indicator" HorizontalAlignment="Left" Margin="1" >
<Grid x:Name="Foreground" >
<Rectangle x:Name="Indicator" Fill="{TemplateBinding Background}" />
<Grid x:Name="Animation" ClipToBounds="true" >
<Rectangle x:Name="PART_GlowRect" Fill="#FF86C7EB"
HorizontalAlignment="Left" Margin="-100,0,0,0" Width="100"/>
</Grid>
</Grid>
</Border>
<Border x:Name="roundBorder" BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="10" />
<TextBlock />
</Grid>
</ControlTemplate>
Run Code Online (Sandbox Code Playgroud)
这导致:

PART_Indicator左边的LightBlue矩形在哪里(它的宽度在ProgressBar控件内部设置,如此处所示,值为20)和roundBorder.
我需要的是PART_Indicator剪辑它roundBorder,导致类似于:
Socket.Disconnect(bool reuse)根据MSDN,程序可以重用套接字.我的问题是:
如果我们决定重用套接字,那意味着它会重用相同的本地端点吗?它会保留该套接字的端口还是仅仅(我不相信它)保存所有对象资源?
如果它实际上只保存资源,它们会被分配给下一个连接吗?如果是这样,发送/接收缓冲区会自动刷新还是有某种方式刷新它们?断断续续地Socket.ShutDown(ShutDown.Both)为我做这件事吗?
我会在什么情况下使用Socket.Disconnect(false)?如果所有目的都是为了重用套接字,这会给予我什么?
c# ×5
wpf ×5
asp.net ×1
clip ×1
clipping ×1
data-binding ×1
datatrigger ×1
eventsetter ×1
finalizer ×1
iis ×1
itemscontrol ×1
lambda ×1
linq-to-xml ×1
listbox ×1
listboxitem ×1
opacitymask ×1
sockets ×1
xml ×1