我在wpf应用程序中工作,我在XAML中创建了一个复选框,然后我的代码在一个类中调用一个函数,在这个函数中有一个if条件,它检查复选框是否被选中但是没有看到复选框在这堂课上,怎么做呢?
非常感谢
编辑:
这是我做的步骤:我在KinectSkeleton的同一项目下创建了ViewModel类,如下所示:ViewModel类:
public class ViewModel
{
public bool IsChecked { get; set; }
public bool is_clicked { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
在KinectSkeleton中我定义了一个属性,如下所示:
public static readonly DependencyProperty ViewModelProperty =
DependencyProperty.Register("ViewModelH", typeof(ViewModel), typeof(KinectSkeleton), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
public ViewModel ViewModelH
{
get
{
return (ViewModel)GetValue(ViewModelProperty);
}
set
{
SetValue(ViewModelProperty, value);
}
}
Run Code Online (Sandbox Code Playgroud)
并且KinectWindow.xaml中的复选框和按钮的代码是:
<Button Content="Calibrate" Height="24" x:Name="Calibrate" x:FieldModifier="public" Width="90" Click="Calibrate_Click" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" HorizontalAlignment="Left" DockPanel.Dock="Left" Panel.ZIndex="0" Padding="0" VerticalAlignment="Center" />
<CheckBox IsChecked="{Binding Mode=TwoWay, Path=IsChecked}" Content="AngleDifference" Height="22" x:Name="AngleDifference" x:FieldModifier="public" Width="117" Checked="AngleDifference_Checked" Unchecked="AngleDifference_Unchecked" HorizontalAlignment="Left" VerticalAlignment="Center" …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试保存包含我从相机返回到本地存储文件夹的jpeg图像的流.正在创建文件,但遗憾的是根本不包含任何数据.这是我正在尝试使用的代码:
public async Task SaveToLocalFolderAsync(Stream file, string fileName)
{
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
StorageFile storageFile = await localFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
using (IRandomAccessStream fileStream = await storageFile.OpenAsync(FileAccessMode.ReadWrite))
{
using (IOutputStream outputStream = fileStream.GetOutputStreamAt(0))
{
using (DataWriter dataWriter = new DataWriter(outputStream))
{
dataWriter.WriteBytes(UsefulOperations.StreamToBytes(file));
await dataWriter.StoreAsync();
dataWriter.DetachStream();
}
await outputStream.FlushAsync();
}
}
}
public static class UsefulOperations
{
public static byte[] StreamToBytes(Stream input)
{
using (MemoryStream ms = new MemoryStream())
{
input.CopyTo(ms);
return ms.ToArray();
}
}
}
Run Code Online (Sandbox Code Playgroud)
任何以这种方式保存文件的帮助都将非常感激 - 我在网上找到的所有帮助都是指保存文本.我正在使用Windows.Storage命名空间,因此它也适用于Windows 8.
我想以某种ListBox ItemTemplate方式对齐某些内容,使其位置不会根据剩余ItemTemplate元素的宽度而改变.
这是我想要实现的截图:

这是我正在尝试使用的XAML:
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Grid Margin="12 12 0 0"
Width="60" Height="60"
VerticalAlignment="Top"
Background="{StaticResource PhoneAccentBrush}">
<Image Source="/Assets/Mystery.png" />
</Grid>
<StackPanel x:Name="ParentStackPanel">
<TextBlock Text="{Binding Name}" Style="{StaticResource PhoneTextLargeStyle}" x:Name="NameText" />
<TextBlock Text="{Binding Owner, StringFormat='by {0}'}"
Style="{StaticResource PhoneTextSmallStyle}" />
<Grid HorizontalAlignment="Left" x:Name="FixedWidthGrid" >
<StackPanel Orientation="Horizontal">
<TextBlock Width="18"
Text="{Binding ContainerSize, Converter={StaticResource ContainerSizeConverter}}"
Style="{StaticResource PhoneTextNormalStyle}" />
<TextBlock Margin="0" Text="{Binding Difficulty, StringFormat='{}{0:N1}'}"
Style="{StaticResource PhoneTextNormalStyle}" />
<TextBlock Margin="0" Text="/"
Style="{StaticResource PhoneTextNormalStyle}" />
<TextBlock Margin="0" Text="{Binding Terrain, StringFormat='{}{0:N1}'}"
Style="{StaticResource PhoneTextNormalStyle}" /> …Run Code Online (Sandbox Code Playgroud) 我在设计器中为自定义活动正确地进行验证时遇到问题.重现行为的最简单示例如下:
我有一个自定义的WF4活动,其中包含存储在字典中的动态参数集合:
[Designer(typeof(DictionaryActivityDesigner))]
public class DictionaryActivity : NativeActivity
{
[Browsable(false)]
public Dictionary<string, InArgument> Arguments { get; set; }
public InArgument<string> StringArg { get; set; }
public DictionaryActivity()
{
Arguments = new Dictionary<string, InArgument>();
}
protected override void Execute(NativeActivityContext context)
{ }
}
Run Code Online (Sandbox Code Playgroud)
在设计器中,我用dinamically创建用于编辑这些参数的表达式文本框.用户可以在单独的模态窗口中定义参数及其类型,但为了简单起见,我修复了此示例中的参数:
public partial class DictionaryActivityDesigner
{
private Dictionary<string, Type> definition;
public DictionaryActivityDesigner()
{
definition = new Dictionary<string, Type>
{
{ "String Arg", typeof(string) },
{ "Int Arg", typeof(int) }
};
InitializeComponent();
}
public void InitializeGrid(Dictionary<string, Type> arguments)
{ …Run Code Online (Sandbox Code Playgroud) 我在其部署的服务器之一上使用Windows身份验证的WCF服务出现问题(它是Windows Server 2008 R2计算机),而在我可以访问的所有其他计算机上运行完美(Windows 7,Windows Server) 2008和Windows Server 2008 R2).我设法用一个非常简单的示例应用程序重现了这个问题,该应用程序或多或少完全排除了我的代码作为问题的原因.
我可以重现问题的最小应用程序是对WCF服务项目模板的一个小修改:
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetData(int value);
}
[AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}\nUsername: {1}",
value,
ServiceSecurityContext.Current == null ?
"<null>" :
ServiceSecurityContext.Current.PrimaryIdentity.Name);
}
}
Run Code Online (Sandbox Code Playgroud)
基本上我启用了ASP.NET兼容性(我需要它,因为实际代码使用HttpHandler进行身份验证)并返回经过身份验证的用户的用户名.
内容web.config如下:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="Windows"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding …Run Code Online (Sandbox Code Playgroud) 有没有办法浏览在模拟器中运行的Windows Phone 8的文件系统,最好是在模拟器运行时?
如果我可以在应用程序运行时访问应用程序本地存储及其他私有文件夹,这将使调试变得更加容易:检查存在的文件,修改它们,添加新文件等.不止一次,这对我来说非常有用适用于Windows 8的Windows应用商店应用.
我有一个页面,其中包含一组垂直文本框.如果其中一个是聚焦的,即使显示屏幕键盘,所有这些都应该是可见的.只有足够的它们都适合键盘上方的可用空间.当底部文本框被聚焦时,页面会自动向上滚动,以便所有页面都可见,但如果顶部文本框被聚焦,则屏幕键盘覆盖底部文本框.
这是我的页面的简化示例:
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<ItemsControl ItemsSource="{Binding List}" Margin="120 140 0 0">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0 10 0 0">
<TextBox Text="{Binding Text, Mode=TwoWay}" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
Run Code Online (Sandbox Code Playgroud)
DataContext 包含10个项目的列表:
public class Item
{
public string Text { get; set; }
}
public class ViewModel
{
public List<Item> List { get; set; }
}
public MainPage()
{
this.InitializeComponent();
DataContext = new ViewModel
{
List = Enumerable.Range(0, 10).Select(i => new Item { Text = i.ToString() }).ToList()
};
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试过几种方法,但都没有成功: …