FX DeviceControl区块链是什么么

>> devicecontrolactivity.java
devicecontrolactivity.java ( 文件浏览 )
* Copyright (C) 2013 The Android Open Source Project
* Licensed under the Apache License, Version 2.0 (the &License&);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an &AS IS& BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
package com.example.bluetooth.
import android.annotation.SuppressL
import android.app.A
import android.bluetooth.BluetoothGattC
import android.bluetooth.BluetoothGattS
import android.content.BroadcastR
import android.content.ComponentN
import android.content.C
import android.content.I
import android.content.IntentF
import android.content.ServiceC
import android.os.B
import android.os.IB
import android.util.L
import android.view.M
import android.view.MenuI
import android.view.V
import android.widget.B
import android.widget.ExpandableListV
import android.widget.SimpleExpandableListA
import android.widget.TextV
import java.util.ArrayL
import java.util.HashM
import java.util.L
import java.util.R
import com.example.bluetooth.le.R;
* For a given BLE device, this Activity provides the user interface to connect,
* display data, and display GATT services and characteristics supported by the
* device. The Activity communicates with {
@code BluetoothLeService
}, which in
* turn interacts with the Bluetooth LE API.
@SuppressLint(&NewApi&)
public class DeviceControlActivity extends Activity {
private final static String TAG = DeviceControlActivity.class
.getSimpleName();
public static final String EXTRAS_DEVICE_NAME = &DEVICE_NAME&;
public static final String EXTRAS_DEVICE_ADDRESS = &DEVICE_ADDRESS&;
private TextView mConnectionS
private TextView mDataF
private String mDeviceN
private String mDeviceA
private ExpandableListView mGattServicesL
private BluetoothLeService mBluetoothLeS
private ArrayList&ArrayList&BluetoothGattCharacteristic&& mGattCharacteristics = new ArrayList&ArrayList&BluetoothGattCharacteristic&&();
private boolean mConnected =
private BluetoothGattCharacteristic mNotifyC
private final String LIST_NAME = &NAME&;
private final String LIST_UUID = &UUID&;
private Button btnW
// Code to manage Service lifecycle.
private final ServiceConnection mServiceConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName componentName,
IBinder service) {
mBluetoothLeService = ((BluetoothLeService.LocalBinder) service)
.getService();
if (!mBluetoothLeService.initialize()) {
Log.e(TAG, &Unable to initialize Bluetooth&);
// Automatically connects to the device upon successful start-up
// initialization.
mBluetoothLeService.connect(mDeviceAddress);
public void onServiceDisconnected(ComponentName componentName) {
mBluetoothLeService =
// Handles various events fired by the Service.
// ACTION_GATT_CONNECTED: connected to a GATT server.
// ACTION_GATT_DISCONNECTED: disconnected from a GATT server.
// ACTION_GATT_SERVICES_DISCOVERED: discovered GATT services.
// ACTION_DATA_AVAILABLE: received data from the device. This can be a
// result of read
// or notification operations.
private final BroadcastReceiver mGattUpdateReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
System.out.println(&action = & + action);
if (BluetoothLeService.ACTION_GATT_CONNECTED.equals(action)) {
mConnected =
updateConnectionState(R.string.connected);
invalidateOptionsMenu();
} else if (BluetoothLeService.ACTION_GATT_DISCONNECTED
.equals(action)) {
mConnected =
updateConnectionState(R.string.disconnected);
invalidateOptionsMenu();
clearUI();
} else if (BluetoothLeService.ACTION_GATT_SERVICES_DISCOVERED
.equals(action)) {
// Show all the supported services and characteristics on the
// user interface.
displayGattServices(mBluetoothLeService
.getSupportedGattServices());
} else if (BluetoothLeService.ACTION_DATA_AVAILABLE.equals(action)) {
displayData(intent
.getStringExtra(BluetoothLeService.EXTRA_DATA));
// If a given GATT characteristic is selected, check for supported features.
// This sample
// demonstrates 'Read' and 'Notify' features. See
// http://d.android.com/reference/android/bluetooth/BluetoothGatt.html for
// the complete
// list of supported characteristic features.
private final ExpandableListView.OnChildClickListener servicesListClickListner = new ExpandableListView.OnChildClickListener() {
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
if (mGattCharacteristics != null) {
final BluetoothGattCharacteristic characteristic = mGattCharacteristics
.get(groupPosition).get(childPosition);
final int charaProp = characteristic.getProperties();
System.out.println(&charaProp = & + charaProp + &,UUID = &
+ characteristic.getUuid().toString());
Random r = new Random();
if (characteristic.getUuid().toString()
.equals(&0000fff2-00-fb&)) {
int time= 0;
while((time=r.nextInt(9))&=0){
String data = &31&;
characteristic.setValue(data.getBytes());
mBluetoothLeService.wirteCharacteristic(characteristic);
if (characteristic.getUuid().toString()
.equals(&0000fff1-00-fb&)) {
int R = r.nextInt(255);
int G = r.nextInt(255);
int B = r.nextInt(255);
int BB = r.nextInt(100);
String data = R + &,& + G + &,& + B + &,& + BB;
while (data.length() & 18) {
data += &,&;
System.out.println(data);
String dd = &00&;
characteristic.setValue(dd.getBytes());
mBluetoothLeService.wirteCharacteristic(characteristic);
if (characteristic.getUuid().toString()
.equals(&0000fff3-00-fb&)) {
int R = r.nextInt(255);
int G = r.nextInt(255);
int B = r.nextInt(255);
int BB = r.nextInt(100);
String data = R + &,& + G + &,& + B + &,& + BB;
while (data.length() & 18) {
data += &,&;
System.out.println(&RT&);
characteristic.setValue(&RT&.getBytes());
mBluetoothLeService.wirteCharacteristic(characteristic);
if (characteristic.getUuid().toString()
.equals(&0000fff5-00-fb&)) {
characteristic.setValue(&S&.getBytes());
mBluetoothLeService.wirteCharacteristic(characteristic);
System.out.println(&send S&);
if ((charaProp & BluetoothGattCharacteristic.PROPERTY_READ) & 0) {
// If there is an active notification on a
// characteristic, clear
// it first so it doesn't update the data field on the
// user interface.
if (mNotifyCharacteristic != null) {
mBluetoothLeService.setCharacteristicNotification(
mNotifyCharacteristic, false);
mNotifyCharacteristic =
mBluetoothLeService.readCharacteristic(characteristic);
if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) & 0) {
if (characteristic.getUuid().toString().equals(&0000fff6-00-fb&)||characteristic.getUuid().toString().equals(&0000fff4-00-fb&)) {
System.out.println(&enable notification&);
mNotifyCharacteristic =
mBluetoothLeService.setCharacteristicNotification(
characteristic, true);
private void clearUI() {
mGattServicesList.setAdapter((SimpleExpandableListAdapter) null);
mDataField.setText(R.string.no_data);
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gatt_services_characteristics);
final Intent intent = getIntent();
mDeviceName = intent.getStringExtra(EXTRAS_DEVICE_NAME);
mDeviceAddress = intent.getStringExtra(EXTRAS_DEVICE_ADDRESS);
btnWrite = (Button)findViewById(R.id.btnWrite);
// Sets up UI references.
((TextView) findViewById(R.id.device_address)).setText(mDeviceAddress);
mGattServicesList = (ExpandableListView) findViewById(R.id.gatt_services_list);
mGattServicesList.setOnChildClickListener(servicesListClickListner);
mConnectionState = (TextView) findViewById(R.id.connection_state);
mDataField = (TextView) findViewById(R.id.data_value);
getActionBar().setTitle(mDeviceName);
getActionBar().setDisplayHomeAsUpEnabled(true);
Intent gattServiceIntent = new Intent(this, BluetoothLeService.class);
boolean bll = bindService(gattServiceIntent, mServiceConnection,
BIND_AUTO_CREATE);
if (bll) {
System.out.println(&---------------&);
System.out.println(&===============&);
protected void onResume() {
super.onResume();
registerReceiver(mGattUpdateReceiver, makeGattUpdateIntentFilter());
if (mBluetoothLeService != null) {
final boolean result = mBluetoothLeService.connect(mDeviceAddress);
Log.d(TAG, &Connect request result=& + result);
protected void onPause() {
super.onPause();
unregisterReceiver(mGattUpdateReceiver);
protected void onDestroy() {
super.onDestroy();
unbindService(mServiceConnection);
mBluetoothLeService =
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.gatt_services, menu);
if (mConnected) {
menu.findItem(R.id.menu_connect).setVisible(false);
menu.findItem(R.id.menu_disconnect).setVisible(tru
(文件超长,未完全显示,请下载后阅读剩余部分)
展开> <收缩
下载源码到电脑,阅读使用更方便
还剩0行未阅读,继续阅读 ▼
Sponsored links
源码文件列表
温馨提示: 点击源码文件名可预览文件内容哦 ^_^
.classpath475.00 B23-09-13 14:30
.project848.00 B05-09-13 17:29
org.eclipse.core.resources.prefs55.00 B13-09-13 13:50
org.eclipse.jdt.core.prefs177.00 B05-09-13 17:29
1.27 kB12-09-13 17:25
1.27 kB21-11-13 14:35
Bluetooth4_3.apk231.82 kB21-11-13 15:05
BluetoothLeService$1.class4.07 kB02-01-14 10:08
BluetoothLeService$LocalBinder.class703.00 B02-01-14 10:08
BluetoothLeService.class8.63 kB02-01-14 10:08
BuildConfig.class357.00 B02-01-14 10:08
DeviceControlActivity$1.class1.87 kB02-01-14 10:08
DeviceControlActivity$2.class2.45 kB02-01-14 10:08
DeviceControlActivity$3.class4.28 kB02-01-14 10:08
DeviceControlActivity$4.class931.00 B02-01-14 10:08
DeviceControlActivity.class11.18 kB02-01-14 10:08
DeviceScanActivity$1$1.class1.34 kB02-01-14 10:08
DeviceScanActivity$1.class1.28 kB02-01-14 10:08
DeviceScanActivity$2.class1.24 kB02-01-14 10:08
DeviceScanActivity$LeDeviceListAdapter.class2.96 kB02-01-14 10:08
DeviceScanActivity$ViewHolder.class517.00 B02-01-14 10:08
DeviceScanActivity.class6.16 kB02-01-14 10:08
MainActivity.class829.00 B02-01-14 10:08
R$attr.class358.00 B04-03-14 14:33
R$dimen.class479.00 B04-03-14 14:33
R$drawable.class425.00 B04-03-14 14:33
R$id.class770.00 B04-03-14 14:33
R$layout.class569.00 B04-03-14 14:33
R$menu.class443.00 B04-03-14 14:33
R$string.class1.00 kB04-03-14 14:33
R$style.class449.00 B04-03-14 14:33
R.class733.00 B04-03-14 14:33
SampleGattAttributes.class1.43 kB02-01-14 10:08
classes.dex637.69 kB21-11-13 15:05
android-support-v4-639cbeb58bbc930dbb861.jar206.37 kB21-11-13 14:37
jarlist.cache120.00 B04-03-14 14:31
ic_launcher.png723.00 B21-11-13 14:37
ic_launcher.png573.00 B21-11-13 14:37
ic_launcher.png878.00 B21-11-13 14:37
ic_launcher.png1.09 kB21-11-13 14:37
resources.ap_11.52 kB21-11-13 14:37
166.00 B21-11-13 14:35
4.13 kB04-03-14 14:33
ic_launcher-web.png5.32 kB05-09-13 17:29
android-support-v4.jar543.16 kB05-09-13 17:29
781.00 B05-09-13 17:29
project.properties563.00 B23-09-13 14:30
ic_launcher.png642.00 B05-09-13 17:29
ic_launcher.png510.00 B05-09-13 17:29
ic_launcher.png809.00 B05-09-13 17:29
ic_launcher.png1.13 kB05-09-13 17:29
942.00 B05-09-13 17:36
658.00 B05-09-13 17:37
4.07 kB19-11-13 16:45
1.24 kB05-09-13 17:36
1.24 kB05-09-13 17:38
1.25 kB05-09-13 17:38
220.00 B05-09-13 17:29
1.62 kB05-09-13 17:37
697.00 B05-09-13 17:29
203.00 B05-09-13 17:29
277.00 B05-09-13 17:29
334.00 B05-09-13 17:29
391.00 B05-09-13 17:29
13.03 kB24-09-13 12:19
13.81 kB21-11-13 15:05
8.84 kB13-09-13 15:10
576.00 B05-09-13 17:44
1.64 kB24-09-13 10:54
&le&0.00 B02-01-14 10:08
&bluetooth&0.00 B02-01-14 10:08
&le&0.00 B21-11-13 14:35
&le&0.00 B19-11-13 15:58
&example&0.00 B02-01-14 10:08
&bluetooth&0.00 B21-11-13 14:35
&bluetooth&0.00 B19-11-13 15:58
&com&0.00 B02-01-14 10:08
&drawable-hdpi&0.00 B21-11-13 14:37
&drawable-mdpi&0.00 B21-11-13 14:37
&drawable-xhdpi&0.00 B21-11-13 14:37
&drawable-xxhdpi&0.00 B21-11-13 14:37
&example&0.00 B21-11-13 14:35
&example&0.00 B19-11-13 15:58
&classes&0.00 B02-01-14 10:08
&dexedLibs&0.00 B21-11-13 14:37
&res&0.00 B21-11-13 14:37
&com&0.00 B21-11-13 14:35
&drawable-hdpi&0.00 B19-11-13 15:58
&drawable-ldpi&0.00 B05-09-13 17:29
&drawable-mdpi&0.00 B19-11-13 15:58
&drawable-xhdpi&0.00 B19-11-13 15:58
&drawable-xxhdpi&0.00 B19-11-13 15:58
&layout&0.00 B19-11-13 15:58
&menu&0.00 B19-11-13 15:58
&values&0.00 B19-11-13 15:58
&values-sw600dp&0.00 B19-11-13 15:58
&values-sw720dp-land&0.00 B19-11-13 15:58
&values-v11&0.00 B19-11-13 15:58
&values-v14&0.00 B19-11-13 15:58
&com&0.00 B19-11-13 15:58
&.settings&0.00 B19-11-13 15:58
&assets&0.00 B05-09-13 17:29
&bin&0.00 B25-11-13 08:08
&gen&0.00 B21-11-13 14:35
&libs&0.00 B19-11-13 15:58
&res&0.00 B19-11-13 15:58
&src&0.00 B19-11-13 15:58
&Bluetooth4_3&0.00 B19-11-13 15:58
Sponsored links
评价成功,多谢!
下载Bluetooth4_3.rar
CodeForge积分(原CF币)全新升级,功能更强大,使用更便捷,不仅可以用来下载海量源代码马上还可兑换精美小礼品了
您的积分不足
支付宝优惠套餐快速获取 30 积分
10积分 / ¥100
30积分 / ¥200原价 ¥300 元
100积分 / ¥500原价 ¥1000 元
订单支付完成后,积分将自动加入到您的账号。以下是优惠期的人民币价格,优惠期过后将恢复美元价格。
支付宝支付宝付款
微信钱包微信付款
更多付款方式:、
您本次下载所消耗的积分将转交上传作者。
同一源码,30天内重复下载,只扣除一次积分。
鲁ICP备号-3 runtime:Elapsed:ms 5.8
登录 CodeForge
还没有CodeForge账号?
Switch to the English version?
^_^"呃 ...
Sorry!这位大神很神秘,未开通博客呢,请浏览一下其他的吧&>&VB编写系统硬 件设备控制工具--DeviceControl
VB编写系统硬 件设备控制工具--DeviceControl
上传大小:42KB
VB编写系统硬 件设备控制工具--DeviceControl
综合评分:4
下载个数:
{%username%}回复{%com_username%}{%time%}\
/*点击出现回复框*/
$(".respond_btn").on("click", function (e) {
$(this).parents(".rightLi").children(".respond_box").show();
e.stopPropagation();
$(".cancel_res").on("click", function (e) {
$(this).parents(".res_b").siblings(".res_area").val("");
$(this).parents(".respond_box").hide();
e.stopPropagation();
/*删除评论*/
$(".del_comment_c").on("click", function (e) {
var id = $(e.target).attr("id");
$.getJSON('/index.php/comment/do_invalid/' + id,
function (data) {
if (data.succ == 1) {
$(e.target).parents(".conLi").remove();
alert(data.msg);
$(".res_btn").click(function (e) {
var parentWrap = $(this).parents(".respond_box"),
q = parentWrap.find(".form1").serializeArray(),
resStr = $.trim(parentWrap.find(".res_area_r").val());
console.log(q);
//var res_area_r = $.trim($(".res_area_r").val());
if (resStr == '') {
$(".res_text").css({color: "red"});
$.post("/index.php/comment/do_comment_reply/", q,
function (data) {
if (data.succ == 1) {
var $target,
evt = e || window.
$target = $(evt.target || evt.srcElement);
var $dd = $target.parents('dd');
var $wrapReply = $dd.find('.respond_box');
console.log($wrapReply);
//var mess = $(".res_area_r").val();
var mess = resS
var str = str.replace(/{%header%}/g, data.header)
.replace(/{%href%}/g, 'http://' + window.location.host + '/user/' + data.username)
.replace(/{%username%}/g, data.username)
.replace(/{%com_username%}/g, data.com_username)
.replace(/{%time%}/g, data.time)
.replace(/{%id%}/g, data.id)
.replace(/{%mess%}/g, mess);
$dd.after(str);
$(".respond_box").hide();
$(".res_area_r").val("");
$(".res_area").val("");
$wrapReply.hide();
alert(data.msg);
}, "json");
/*删除回复*/
$(".rightLi").on("click", '.del_comment_r', function (e) {
var id = $(e.target).attr("id");
$.getJSON('/index.php/comment/do_comment_del/' + id,
function (data) {
if (data.succ == 1) {
$(e.target).parent().parent().parent().parent().parent().remove();
$(e.target).parents('.res_list').remove()
alert(data.msg);
//填充回复
function KeyP(v) {
var parentWrap = $(v).parents(".respond_box");
parentWrap.find(".res_area_r").val($.trim(parentWrap.find(".res_area").val()));
评论共有3条
不错,可以找到很多硬件驱动
很有用的VB程序,值得借鉴一下
不错,可以找到很多硬件驱动。呵呵!!!
VIP会员动态
CSDN下载频道资源及相关规则调整公告V11.10
下载频道用户反馈专区
下载频道积分规则调整V1710.18
spring mvc+mybatis+mysql+maven+bootstrap 整合实现增删查改简单实例.zip
资源所需积分/C币
当前拥有积分
当前拥有C币
输入下载码
为了良好体验,不建议使用迅雷下载
VB编写系统硬 件设备控制工具--DeviceControl
会员到期时间:
剩余下载个数:
剩余积分:0
为了良好体验,不建议使用迅雷下载
积分不足!
资源所需积分/C币
当前拥有积分
您可以选择
程序员的必选
绿色安全资源
资源所需积分/C币
当前拥有积分
当前拥有C币
为了良好体验,不建议使用迅雷下载
资源所需积分/C币
当前拥有积分
当前拥有C币
为了良好体验,不建议使用迅雷下载
资源所需积分/C币
当前拥有积分
当前拥有C币
您的积分不足,将扣除 10 C币
为了良好体验,不建议使用迅雷下载
无法举报自己的资源
你当前的下载分为234。
你还不是VIP会员
开通VIP会员权限,免积分下载
你下载资源过于频繁,请输入验证码
您因违反CSDN下载频道规则而被锁定帐户,如有疑问,请联络:!
若举报审核通过,可返还被扣除的积分
被举报人:
举报的资源分:
请选择类型
资源无法下载 ( 404页面、下载失败、资源本身问题)
资源无法使用 (文件损坏、内容缺失、题文不符)
侵犯版权资源 (侵犯公司或个人版权)
虚假资源 (恶意欺诈、刷分资源)
含色情、危害国家安全内容
含广告、木马病毒资源
*详细原因:
VB编写系统硬 件设备控制工具--DeviceControlContentControl 与 ViewModel (一) - E不小心 - 博客园
前阵子有人问我MVVM模式下,在View中嵌套View,切换View。想一想还是写下来吧。
主要就是用到 ContentControl 和 DataTemplate,这算是一种 ViewModel First 的思想吧。
其实好多MVVM的框架,也都提供这样的功能。在ContentControl绑定ViewModel,就可以显示 对应的View。比如&Caliburn.Micro(CM框架).
MVVMLight应该是没有提供的,对他我本身不是很熟,以前知道他很轻,看过原码,真心没有多少,最近在RT中用了下,发现它也加入了IOC的东东。
以下代码没用使用任何第三方框架。
using System.Windows.I
namespace ContentDemo
// ViewModelBase 只是实现了 INotifyPropertyChanged
class MainViewModel : ViewModelBase
{     // 如果有IOC这块的东西 可以用IOC代替。
private readonly FirstViewModel _firstViewModel = new FirstViewModel();
private readonly SecondViewModel _secondViewModel = new SecondViewModel();
private object _viewM
/// &summary&
/// 要绑定和切换的ViewModel
/// &/summary&
public object ViewModel
get { return _viewM }
if (_viewModel == value)
_viewModel =
OnPropertyChanged();
// 下面两个 Command只是为了 切换 ViewModel用的。
private ICommand _firstC
public ICommand FirstCommand
return _firstCommand = _firstCommand ?? new DelegateCommand(obj =&
ViewModel = _firstViewM
private ICommand _secondC
public ICommand SecondCommand
return _secondCommand = _secondCommand ?? new DelegateCommand(obj =&
ViewModel = _secondViewM
这个是ViewModel的代码,ViewModel OK啦,我们就来写View了。
&Window x:Class="ContentDemo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ContentDemo"
Title="MainWindow" Height="350" Width="525"&
&Window.Resources&
&local:MainViewModel x:Key="MainViewModel" /&
&DataTemplate DataType="{x:Type local:FirstViewModel}"&
&local:FirstView /&
&/DataTemplate&
&DataTemplate DataType="{x:Type local:SecondViewModel}"&
&local:SecondView /&
&/DataTemplate&
&/Window.Resources&
&Grid DataContext="{StaticResource MainViewModel}"&
&Grid.RowDefinitions&
&RowDefinition /&
&RowDefinition Height="Auto"/&
&/Grid.RowDefinitions&
&Grid.ColumnDefinitions&
&ColumnDefinition /&
&ColumnDefinition /&
&/Grid.ColumnDefinitions&
&ContentControl Grid.ColumnSpan="2" Content="{Binding Path=ViewModel}" /&
&Button Grid.Row="1" Grid.Column="0" Content="ViewModel
1" Command="{Binding Path=FirstCommand}"/&
&Button Grid.Row="1" Grid.Column="1" Content="ViewModel
2" Command="{Binding Path=SecondCommand}"/&
其实这也没什么,关键的地方就是,ContentControl的Content要绑定ViewModel,这是用来显示和切换ViewModel对应的View的。
在资源中加入DataTempalte,DataType设置成ViewModel的类型,DataTemplate 写上你的View,只样就可以自动匹配的你ViewModel啦。
注:在WinRT中的DataTemplate是没有DataType属性的,SL里有没有,我记不住了。可以用我最下面说的办法来弄。
下在是 二个ViewModel和View的代码,都很简答,就是为了展示一下。
class FirstViewModel
public string Content { get; set; }
public FirstViewModel()
Content = "第一个ViewModel";
class SecondViewModel
public string Content { get; set; }
public SecondViewModel()
Content = "第二个ViewModel";
&UserControl x:Class="ContentDemo.FirstView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"&
&Border Background="DarkGray"&
&TextBlock Text="{Binding Path=Content}"
HorizontalAlignment="Center"
VerticalAlignment="Center"/&
&/UserControl&
&UserControl x:Class="ContentDemo.SecondView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"&
&Border Background="DarkMagenta"&
&TextBlock Text="{Binding Path=Content}"
HorizontalAlignment="Center"
VerticalAlignment="Center"/&
&/UserControl&
这样,我们切换MailViewModel中的ViewModel的时候,就会换成不同的UI了,DataTemplate 中内容的DataContext 也会是相应的ViewModel。
写的很不好,我的语文虽然不是体育老师交的,也是数学老教交出来的。
还是直接源码吧:
源码是2013写的,打不开的自行修改 项目文件或复制源码到新项目吧。
可能现在有人发现了,这样每一个用到的ViewModel和都至少写上一个DataTemplate,这样很不爽,重复的代码太多啦。
下一步的关键就是 DataTemplateSelector。说到这个,大家可能就会了,下篇再分解吧。嘿嘿
转载请注明出处:&

我要回帖

更多关于 吃鸡是什么游戏 的文章

 

随机推荐