




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
第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("","");
//若字符個(gè)數(shù)為奇數(shù),補(bǔ)一個(gè)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等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年中國(guó)6-氨基己酸數(shù)據(jù)監(jiān)測(cè)報(bào)告
- 2025年中國(guó)15%甲硫.霉威懸浮劑數(shù)據(jù)監(jiān)測(cè)報(bào)告
- 2025至2030年中國(guó)高效脫硫麻石水膜除塵器市場(chǎng)分析及競(jìng)爭(zhēng)策略研究報(bào)告
- 2025至2030年中國(guó)門框滾壓成型機(jī)市場(chǎng)分析及競(jìng)爭(zhēng)策略研究報(bào)告
- 2025至2030年中國(guó)金屬清洗兼防銹劑市場(chǎng)分析及競(jìng)爭(zhēng)策略研究報(bào)告
- 2025至2030年中國(guó)視頻資料服務(wù)管理系統(tǒng)市場(chǎng)分析及競(jìng)爭(zhēng)策略研究報(bào)告
- 2025至2030年中國(guó)膠帶輸送自動(dòng)調(diào)偏器市場(chǎng)分析及競(jìng)爭(zhēng)策略研究報(bào)告
- 2025至2030年中國(guó)管道自動(dòng)增壓泵市場(chǎng)分析及競(jìng)爭(zhēng)策略研究報(bào)告
- 2025至2030年中國(guó)白晶粉市場(chǎng)分析及競(jìng)爭(zhēng)策略研究報(bào)告
- 2025至2030年中國(guó)浮雕雙龍棍劍市場(chǎng)分析及競(jìng)爭(zhēng)策略研究報(bào)告
- 精選天津市初中地理會(huì)考試卷及答案
- 無創(chuàng)腦血氧監(jiān)護(hù)儀技術(shù)審評(píng)報(bào)告
- 糖尿病足的診斷與治療ppt課件
- 非車險(xiǎn)銷售人員基礎(chǔ)培訓(xùn)系列第一講走進(jìn)非車險(xiǎn)世界
- 比選申請(qǐng)文件模板
- pt1000熱電阻分度表
- 彩盒成品檢驗(yàn)標(biāo)準(zhǔn)
- 落地單排腳手架
- 新人教五年級(jí)數(shù)學(xué)下冊(cè)
- 高層購(gòu)物中心AAC墻體板材施工方案
- 無縫鋼管廠設(shè)備介紹
評(píng)論
0/150
提交評(píng)論