我正在研究"学习计划"并使用Code Rush重构工具和我的学习.随着Code Rush的最新更新,它一直建议在我的程序中实现IDisposable.我知道MSDN对IDisposable的看法,我对它的作用有一个真正基本的了解,但因为我不知道实现它的所有含义我一直忽略了这个建议.今天我决定更多地了解它并同意推荐.
这是它添加到我的程序中的内容.
class Program : IDisposable
{
static Service _proxy;
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (disposing)
if (_proxy != null)
{
_proxy.Dispose();
_proxy = null;
}
}
~Program()
{
Dispose(false);
}
Run Code Online (Sandbox Code Playgroud)
所以我的问题就是这个.这样做我需要做些什么来获得IDisposable的优势,还是我需要在代码中做一些事情才能使它工作?我在其上设置了一个断点,并且从未通过调试器到达它,因此要么不需要它,要么我没有按照预期的方式使用它.有人可以说明这对我的影响或我应该如何使用它以便它确实为我做了些什么?
我有一个 UWP,我从 XML 文件加载并在 GridView 中显示它,我试图以一种允许我在所有可用空间中堆叠和包装项目的方式启用滚动条,如下图所示。我遇到的问题是我无法弄清楚如何启用滚动条,以便我可以滚动框直到到达列表的末尾。
到目前为止,我已经完成了您在图片中看到的操作,它以我想要的方式包装,但它填充了所有可用空间,并且不允许您垂直或水平滚动(我只想以一种方式滚动,但我试图看看我是否可以走任何一条路)。通过大量的反复试验,我能够让它一次滚动一行或一列到列表的末尾,但这也不是想要的结果。这是我现在使用 XAML 的地方(屏幕截图的精简版)。
<GridView x:Name="DataGrid1">
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsWrapGrid Orientation="Horizontal"
ScrollViewer.HorizontalScrollBarVisibility="Visible"
ScrollViewer.VerticalScrollBarVisibility="Disabled" />
</ItemsPanelTemplate>
</GridView.ItemsPanel>
<GridView.ItemTemplate>
<DataTemplate>
<Border Width="270"
Height="200"
Margin="5"
BorderBrush="Black"
BorderThickness="2">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="70" />
<ColumnDefinition Width="100*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0"
Grid.Column="0"
Grid.ColumnSpan="2"
Background="#87CEFA">
<TextBlock Margin="2"
HorizontalAlignment="Center"
FontSize="16"
FontWeight="Bold"
Text="{Binding Company}" />
</StackPanel>
<TextBlock Grid.Row="1"
Grid.Column="0"
Margin="2"
HorizontalAlignment="Right"
FontWeight="Bold"
Text="Code: " />
<TextBlock Grid.Row="1"
Grid.Column="1"
Margin="2"
Text="{Binding Code}" />
</Grid>
</Border>
</DataTemplate>
</GridView.ItemTemplate>
</GridView> …Run Code Online (Sandbox Code Playgroud) 我正在尝试做一些简单的数学运算,应该是从request.ReponseText返回的数字和输入文本框的数字.这是代码
//var storedMiles : number = new Number(request.responseText);
var storedMiles = new Number(request.responseText);
var enteredMiles = parseInt((<HTMLTextAreaElement>document.getElementById("txtMiles")).value);
var intervalMiles = (enteredMiles - storedMiles);
Run Code Online (Sandbox Code Playgroud)
我从TypeScript编译器得到的错误是:
The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
Run Code Online (Sandbox Code Playgroud)
编译器把波浪线下enteredMiles的var intervalMiles = (enteredMiles - storedMiles);线.
我无法在文档中找到有关如何纠正该错误的任何内容.我也没有找到自己进行转换的方法.TypeScript编译器需要什么才能同时处理数字enteredMiles和storedMiles"数字"类型,以便我可以进行数学运算?
我试图将一个对象的两个不同实例绑定到一个表单的不同部分,我没有找到任何帮助,如何做到这一点,这使我相信我走错了路.特别是因为这似乎是WPF绑定中非常常见的任务.
所以,在我继续走这条路之前,我想问这个问题.是否可以使用两个不同的DataContexts绑定两个不同的控件?例如,我的表单上有一个Home团队和一个Visitors团队,我想为他们两个使用相同的对象.我原本以为只需创建两个DataContexts(DataContext1和DataContext2),然后为每个设置绑定,但找不到类似的样本.这就是我所拥有的,这是我想要做的一个人为的例子.
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Results team1 = new Results() { StoreId = 101, Score = 10 };
Results team2 = new Results() { StoreId = 102, Score = 15 };
this.DataContext = team1;
//this.DataContext = team2;
}
}
Run Code Online (Sandbox Code Playgroud) 我正在研究UWP应用程序,我正在尝试使用GridView中的SelectedItem的值.因此,正如我通常使用WPF一样,我进入XAML并在XAML中键入我的事件名称,让VS为我创建代码中的事件.
<GridView x:Name="DataGrid1"
ItemClick="dg_ItemClick">
<!-- Just -->
<!-- Some -->
<!-- Normal -->
<!-- XAML -->
</GridView>
Run Code Online (Sandbox Code Playgroud)
并且VS创建的事件看起来像这样
private void dg_ItemClick(object sender, Windows.UI.Xaml.Controls.ItemClickEventArgs e)
{
Biz.Customer cust = e.ClickedItem as Biz.Customer;
var messageDialog2 = new MessageDialog(cust.Code, cust.Company);
messageDialog2.ShowAsync();
}
Run Code Online (Sandbox Code Playgroud)
我马上在Windows.UI.Xaml.Controls部分的UI下面得到一条红色的波浪线.在页面顶部有一个使用包括它,VS不会添加任何其他UWP引用.
通过将ItemClickEventArgs更改为RoutedEvenArgs,我可以将错误消除,就像我在应用程序的其他部分中消失一样,但在这种情况下,我确实需要将ClickedItem作为参数传递给后面的代码.
我刚刚与其他人开始谈论UWP并且他们说他们在其他cLick事件上遇到了同样的问题.那么,我们都做错了什么,或者我们的应用程序中是否存在需要识别UI所需的东西?
我得到的完整错误是这样的:错误CS0234名称空间'app name'中不存在类型或命名空间名称'UI'(您是否缺少程序集引用?)
我最近从VB切换到C#,并且在大多数情况下,能够毫无困难地进行转换.目前我正在努力将VB.Net程序转换为C#,并且遇到包含Linq的几个代码块时遇到问题.
这是我遇到问题的VB.Net代码行之一:
Dim emails = From em In dt Group By email = em(1) Into Emailers = Group
Run Code Online (Sandbox Code Playgroud)
我试图用C#做同样的事情:
var emails =
from em in dt
group emails = em[1]
into Emailers = group;
Run Code Online (Sandbox Code Playgroud)
我在dt上遇到编译错误,它说找不到源类型'System.Data.DataTable'的查询模式的实现.'找不到GroupBy'.VS在整个Emailers = group中也存在问题;
我试图使用我的搜索中的示例来解决这个问题但是却无法做到正确.该怎么转换?
我正在研究一些基于使用jQuery的教程的代码$(document).ready,它会在页面加载(或文档准备好)后立即开始工作.代码是非常标准的(从我对jQuery的了解很少)并且在页面加载时可以正常工作.
$(document).ready(function () {
// Do stuff here
});
Run Code Online (Sandbox Code Playgroud)
但现在我想改变它,以便代码从函数运行.我的第一个想法是我可以将功能更改为此
$(function dothis() {
// Do stuff here
});
Run Code Online (Sandbox Code Playgroud)
然后用dothis()调用它; 但当我这样做时,我得到一个"dothis未定义"错误.我也尝试了几种不同的方式,但却无法解决这个问题.我需要做什么才能使我的工作方式符合我的要求?
function searchCustomers() {
var searchvalue = document.getElementById('searchText2').value;
var searchtype = document.getElementById('searchType2').value;
//Just checking to make sure this part is working...
//alert(searchtype + ' ' + searchvalue)
// Run the "Do Stuff here"
var showDiv = document.getElementById('divCustomerGrid');
showDiv.style.display = 'block';
};
Run Code Online (Sandbox Code Playgroud) 我一直用CN_作为常量的前缀,如下所示,但我现在正在编写接受标准的编码,我发现这个标准链接在这个网站上.标准说我应该删除CN_为我的常量.因此,通过下面的示例,如果我将CN_NetPrice更改为NetPrice,我将与同名的method属性发生冲突.显然我不能这样做所以我留下了一个问题.我是否有命名约定问题,或者我的代码一般有问题吗?
public class TicketInformation
{
private const string CN_StartDate = "StartDate";
private const string CN_EndDate = "EndDate";
private const string CN_NetPrice = "NetPrice";
private const string CN_NetTotalPrice = "NetTotalPrice";
private const string CN_Tickets = "Tickets";
public decimal NetPrice { get; set; }
public decimal NetTotalPrice { get; set; }
public decimal Tickets { get; set; }
public static TicketInformation Create(DateTime startDate, DateTime endDate)
{
try
{
TicketInformation ti = new TicketInformation();
using (DataTable dt = DAC.ExecuteDataTable(
"GetAllTicketInformationSelect",
DAC.Parameter(CN_StartDate, startDate),
DAC.Parameter(CN_EndDate, …Run Code Online (Sandbox Code Playgroud) c# ×5
javascript ×2
uwp ×2
xaml ×2
coderush ×1
data-binding ×1
gridview ×1
idisposable ×1
jquery ×1
linq ×1
refactoring ×1
typescript ×1
vb.net ×1
wpf ×1