




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
第C#實(shí)現(xiàn)串口調(diào)試工具bytehi=arr[0],lo=arr[1];
returnConvert.ToString(isReversehi+lo*0x100:hi*0x100+lo,16).ToUpper().PadLeft(4,'0');
catch(Exceptionex){throw(ex);}
publicstaticstringByteToString(byte[]arr)
returnByteToString(arr,true);
catch(Exceptionex){throw(ex);}
#endregion
#regionStringToHexString
publicstaticstringStringToHexString(stringstr)
StringBuilders=newStringBuilder();
foreach(shortcinstr.ToCharArray())
s.Append(c.ToString("X4"));
returns.ToString();
#endregion
#regionStringToHexByte
privatestaticstringConvertChinese(stringstr)
StringBuilders=newStringBuilder();
foreach(shortcinstr.ToCharArray())
if(c=0||c=127)
s.Append(c.ToString("X4"));
else
s.Append((char)c);
returns.ToString();
privatestaticstringFilterChinese(stringstr)
StringBuilders=newStringBuilder();
foreach(shortcinstr.ToCharArray())
if(c0c127)
s.Append((char)c);
returns.ToString();
///summary
///字符串轉(zhuǎn)16進(jìn)制字符數(shù)組
////summary
///paramname="hex"/param
///returns/returns
publicstaticbyte[]StringToHexByte(stringstr)
returnStringToHexByte(str,false);
///summary
///字符串轉(zhuǎn)16進(jìn)制字符數(shù)組
////summary
///paramname="str"/param
///paramname="isFilterChinese"是否過濾掉中文字符/param
///returns/returns
publicstaticbyte[]StringToHexByte(stringstr,boolisFilterChinese)
stringhex=isFilterChineseFilterChinese(str):ConvertChinese(str);
//清除所有空格
hex=hex.Replace("","");
//若字符個數(shù)為奇數(shù),補(bǔ)一個0
hex+=hex.Length%2!=0"0":"";
byte[]result=newbyte[hex.Length/2];
for(inti=0,c=result.Length;ii++)
result[i]=Convert.ToByte(hex.Substring(i*2,2),16);
returnresult;
#endregion
}
WPF技術(shù)點(diǎn):
1.自定義樣式按鈕
Stylex:Key="CommonButtonBase"TargetType="{x:TypeButton}"
SetterProperty="BorderBrush"Value="Transparent"/
SetterProperty="BorderThickness"Value="0"/
SetterProperty="Foreground"Value="{DynamicResource{x:StaticSystemColors.ControlTextBrushKey}}"/
SetterProperty="HorizontalContentAlignment"Value="Center"/
SetterProperty="VerticalContentAlignment"Value="Center"/
SetterProperty="Padding"Value="1"/
SetterProperty="Cursor"Value="Hand"/
SetterProperty="Template"
Setter.Value
ControlTemplateTargetType="{x:TypeButton}"
Borderx:Name="border"BorderBrush="{TemplateBindingBorderBrush}"
CornerRadius="4"
BorderThickness="{TemplateBindingBorderThickness}"
Background="{TemplateBindingBackground}"
SnapsToDevicePixels="true"
ContentPresenterHorizontalAlignment="{TemplateBindingHorizontalContentAlignment}"
Margin="{TemplateBindingPadding}"RecognizesAccessKey="True"
SnapsToDevicePixels="{TemplateBindingSnapsToDevicePixels}"
VerticalAlignment="{TemplateBindingVerticalContentAlignment}"/
/Border
ControlTemplate.Triggers
TriggerProperty="IsEnabled"Value="False"
SetterProperty="Background"Value="#000000"/
SetterProperty="Opacity"Value="0.1"/
/Trigger
TriggerProperty="IsMouseOver"Value="true"
SetterProperty="Foreground"Value="#FFFF00"/
/Trigger
TriggerProperty="IsMouseOver"Value="false"
SetterProperty="Foreground"Value="White"/
/Trigger
/ControlTemplate.Triggers
/ControlTemplate
/Setter.Value
/Setter
/Style
StyleTargetType="{x:TypeButton}"x:Key="Btn0093EABase"BasedOn="{StaticResourceCommonButtonBase}"
SetterProperty="Background"Value="#0093EA"/
SetterProperty="Foreground"Value="White"/
SetterProperty="FontSize"Value="22"/
SetterProperty="Height"Value="40"/
SetterProperty="Margin"Value="5"/
/Style
2.轉(zhuǎn)換器用于綁定按鈕
publicclassFontConverters:IValueConverter
publicobjectConvert(objectvalue,TypetargetType,objectparameter,CultureInfoculture)
if(value!=nullbool.TryParse(value.ToString(),outboolresult))
if(result)
return"關(guān)閉串口";
return"打開串口";
publicobjectConvertBack(objectvalue,TypetargetType,objectparameter,CultureInfoculture)
thrownewNotImplementedException();
}
//用于綁定UI的顏色狀態(tài)顯示publicclassColorConverters:IValueConverter
publicobjectConvert(objectvalue,TypetargetType,objectparameter,CultureInfoculture)
if(value!=nullbool.TryParse(value.ToString(),outboolresult))
if(result)
returnnewSolidColorBrush((Color)System.Windows.Media.ColorConverter.ConvertFromString("#2E8B57"));
returnnewSolidColorBrush((Color)System.Windows.Media.ColorConverter.ConvertFromString("#FF6347"));
publicobjectConvertBack(objectvalue,TypetargetType,objectparameter,CultureInfoculture)
thrownewNotImplementedException();
}
3.引用字體
TextBlockText="#xe6e4;"Margin="20505"FontFamily="pack://application:,,,/Font/#iconfont"
Foreground="White"FontSize="30"VerticalAlignment="Center"/
4.綁定命令和元素
TextBlockText="端口:"/
ComboBoxGrid.Row="0"Grid.Column="2"SelectedItem="{BindingCurrentParameter.Port}"
ItemsSource="{BindingComParameterConfig.Port}"
TextBlockText="波特率:"/
ComboBoxGrid.Row="0"Grid.Column="2"SelectedItem="{BindingCurrentParameter.BaudRdate}"
ItemsSource="{BindingComParameterConfig.BaudRate}"
TextBlockText="數(shù)據(jù)位:"/
ComboBoxGrid.Row="0"Grid.Column="2"SelectedItem="{BindingCurrentParameter.DataBit}"
ItemsSource="{Binding
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 修建建筑公司合同范例
- 亞馬遜店鋪轉(zhuǎn)讓合同范例
- 中文出口銷售合同范例
- 公司工會工作年終總結(jié)模版
- 區(qū)塊鏈技術(shù)在農(nóng)業(yè)產(chǎn)品供應(yīng)鏈中的應(yīng)用及效果分析
- 產(chǎn)品聯(lián)合運(yùn)營合同范例
- 2025年學(xué)校教研工作總結(jié)模版
- 醫(yī)療AI在專科護(hù)理領(lǐng)域的創(chuàng)新實(shí)踐案例分享
- 2025-2030年花皮小提包項(xiàng)目商業(yè)計(jì)劃書
- 區(qū)塊鏈賦能大數(shù)據(jù)打造智能商業(yè)生態(tài)
- 2025年中國脊柱骨水泥行業(yè)市場前景預(yù)測及投資價值評估分析報(bào)告
- 電機(jī)節(jié)能協(xié)議書模板
- 2024年四川西南石油大學(xué)招聘事業(yè)編制輔導(dǎo)員考試真題
- 2025年寧夏吳忠紅寺堡區(qū)公開招聘社區(qū)工作者46人筆試備考題庫及答案解析
- 表型組學(xué)技術(shù)助力作物育種效率提升
- 2025年全民營養(yǎng)周科學(xué)實(shí)現(xiàn)吃動平衡健康中國營養(yǎng)先行課件
- 非標(biāo)自動化設(shè)備設(shè)計(jì)培訓(xùn)
- 行政檢查業(yè)務(wù)培訓(xùn)課件
- 西部計(jì)劃共基試題及答案
- 主題班會少年強(qiáng)則國強(qiáng)紀(jì)念五四青年節(jié)【課件】
- 金融數(shù)學(xué)考試及答案
評論
0/150
提交評論