我尝试过使用Math.Round和MidpointRounding.这似乎没有做我需要的.
例:
52.34567 rounded to 2 decimals UP = 52.35
1.183 rounded to 2 decimals DOWN = 1.18
Run Code Online (Sandbox Code Playgroud)
我需要编写自定义函数吗?
编辑:
我应该更具体一点.
有时我需要像23.567这样的数字来向下舍入到23.56.在这种情况下......
Math.Round(dec, 2, MidpointRounding.AwayFromZero) gives 23.57
Math.Round(dec, 2, MidpointRounding.ToEven) gives 23.57
Run Code Online (Sandbox Code Playgroud)
可能会出现最多9位小数的小数,需要四舍五入到小数点后的1,2,3或甚至4位.
我试图在我的Xaml中绑定几个不同的属性:
<Label Content="{Binding Description}"
Visibility="{Binding Path=DescriptionVisibility,
ElementName=_UserInputOutput}"
FontSize="{Binding Path=FontSizeValue, ElementName=_UserInputOutput}"
HorizontalAlignment="Left" VerticalAlignment="Top" Padding="0" />
Run Code Online (Sandbox Code Playgroud)
您会注意到我在这里使用了两种不同的绑定技术.使用元素名称的工作,另一个不工作.这是代码背后:
public string Description
{
get { return (string)GetValue(DescriptionProperty); }
set { SetValue(DescriptionProperty, value); }
}
public static readonly DependencyProperty DescriptionProperty =
DependencyProperty.Register("Description", typeof(string), typeof(UserControl),
new UIPropertyMetadata(""));
Run Code Online (Sandbox Code Playgroud)
每个Binding都有不同的名称,但大多数都看起来像这样.我希望我的Binding能够使用:
{Binding Description}
Run Code Online (Sandbox Code Playgroud)
代替:
{Binding Path=Description, ElementName=_UserInputOutput}
Run Code Online (Sandbox Code Playgroud)
它只在使用ElementName时才起作用.我需要导出/导入这个XAML,所以我不能拥有ElementName,否则导入将无效.
我认为这是最好的:
{Binding Path=Description, RelativeSource={RelativeSource Self}}
Run Code Online (Sandbox Code Playgroud)
这没用.
有任何想法吗??谢谢!
我正在尝试连接蓝牙LE温度计.连接到设备工作正常.让我失望的唯一部分是gattCallBack,它是onCharacteristicChanged/Read.'setNotification'和描述符'setValue'和'writeDescriptor'都返回true.永远不会调用onCharacteristicChanged来返回值.
我使用了一个名为BLE Scanner的Play商店中非常方便的小程序来帮助我提供有关该设备及其服务和特性的更多信息.
这就是为什么我只是硬编码服务2,特征0.我只是无法弄清楚为什么在writeDescriptor后,我从来没有看到任何回来.有趣的是,我可以使用其他一些特性(一个是温度间隔),我确实收到一个响应(虽然数据是乱码.)
另外,出于好奇,为什么这个特征有两个描述符?
此代码包含在我的MainActivity方法中.不确定这是否会有所作为.我已经看过并尝试了几种方法,但没有运气.
private final BluetoothGattCallback gattCallback = new BluetoothGattCallback()
{
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState)
{ ... }
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status)
{
mGatt = gatt;
List<BluetoothGattService> services = mGatt.getServices();
Log.i("onServicesDiscovered", services.toString());
BluetoothGattCharacteristic characteristic = services.get(2).getCharacteristics().get(0);
mGatt.setCharacteristicNotification(characteristic, true);
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString(CLIENT_CHARACTERISTIC_CONFIG));
descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
mGatt.writeDescriptor(descriptor);
}
@Override
public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status)
{ ... }
@Override
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic)
{ ... }
};
Run Code Online (Sandbox Code Playgroud)
更新:我决定检查onDescriptorWrite方法并记录一些信息. …
我试过了:
certmgrs /add myCert.cer /s /r localMachine root
Run Code Online (Sandbox Code Playgroud)
我尝试了几种变体,如: localMachine trustedPublishers
每次我在命令行上尝试这个时,它只会加载certmgr实用程序窗口.我看不到这个命令行调用做任何事情.
这是我到目前为止:
<Image Source="{Binding ImageSource"} />
<Button Content"Text" ImageSource="path/image.png" />
Run Code Online (Sandbox Code Playgroud)
我知道有些事情不对劲.我想我无法看到ImageSource的定义.
我有几个按钮,只想为每个按钮都有一个独特的图像.我有一个我正在使用的按钮模板,它适用于文本.
<Label Content="TemplateBinding Content" />
Run Code Online (Sandbox Code Playgroud)
感谢你的帮助!
我有一个实现IEqualityComparer的类MyItems并覆盖以下方法:
public bool Equals(MyItems item1, MyItems item2)
{
return (item1.ID == item2.ID && item1.itemName.Equals(item2));
}
public int GetHashCode(MyItems item)
{
return item.ID.GetHashCode() ^ item.itemName.GetHashCode();
}
Run Code Online (Sandbox Code Playgroud)
首先,为什么有GetHashCode必要?我理解压倒这种Equals方法,然而,GetHashCode我的必要性已经无法实现.
其次,这似乎不起作用.我有什么问题吗?在那里我不明白GetHashCode,那可能是我绊倒的地方.
我的问题是......为什么从varchar转换为int?我不确定它想要做什么
CREATE PROCEDURE #myTestProcedure
(
@TransId VARCHAR(15)
)
AS
BEGIN
DECLARE @Result VARCHAR(15);
WITH TestCTE (TransId, AdjRefTransId) AS
(
SELECT TRANSID, ADJREFTRANSID
FROM dbo.MyTable
WHERE TRANSID = @TransId
UNION ALL
SELECT pet.TRANSID, pet.ADJREFTRANSID
FROM dbo.MyTable AS pet
JOIN TestCTE
ON TestCTE.ADJREFTRANSID = pet.TRANSID
)
SELECT @Result =
(
SELECT MAX(MyResult)
FROM dbo.MyOtherTable
WHERE TRANSID = TestCTE.TRANSID
)
FROM TestCTE
WHERE TestCTE.ADJREFTRANSID = ''
RETURN @Result
END
EXEC dbo.#myTestProcedure @TransId = 'MyTransId'
Run Code Online (Sandbox Code Playgroud)
错误:
Msg 245, Level 16, State 1, Procedure #myTestProcedure …Run Code Online (Sandbox Code Playgroud) 程序集可以包含exe吗?
我有一个生成exe的程序,但也使用我创建的.dll.是一个多文件组件?
编辑:
那么我在.NET中读到的有关多文件组件的内容是什么?那些包含.exe和.dll吗?
c# ×3
binding ×2
wpf ×2
.net ×1
android ×1
bluetooth ×1
certificate ×1
gethashcode ×1
image ×1
math ×1
overriding ×1
procedure ×1
sql-server ×1
t-sql ×1
windows ×1