質問編集履歴
1
ソースの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -85,3 +85,373 @@
|
|
85
85
|
Mac Note Pro
|
86
86
|
|
87
87
|
OS X Yosemite(10.10.5)
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
###追加ソース
|
92
|
+
|
93
|
+
[Xamarin(PCL)]TopPage.cs
|
94
|
+
|
95
|
+
```
|
96
|
+
|
97
|
+
using System;
|
98
|
+
|
99
|
+
using Xamarin.Forms;
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
namespace XFBindTest
|
104
|
+
|
105
|
+
{
|
106
|
+
|
107
|
+
public class TopPage : ContentPage
|
108
|
+
|
109
|
+
{
|
110
|
+
|
111
|
+
public TopPage()
|
112
|
+
|
113
|
+
{
|
114
|
+
|
115
|
+
Padding = new Thickness(20);
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
var label = new Label
|
120
|
+
|
121
|
+
{
|
122
|
+
|
123
|
+
Text = "Hello ContentPage",
|
124
|
+
|
125
|
+
};
|
126
|
+
|
127
|
+
var button = new Button
|
128
|
+
|
129
|
+
{
|
130
|
+
|
131
|
+
Text = "push",
|
132
|
+
|
133
|
+
};
|
134
|
+
|
135
|
+
button.Clicked += (sender, e) =>
|
136
|
+
|
137
|
+
{
|
138
|
+
|
139
|
+
label.Text = DependencyService.Get<IGetText>().Text;
|
140
|
+
|
141
|
+
};
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
Content = new StackLayout
|
146
|
+
|
147
|
+
{
|
148
|
+
|
149
|
+
Children = {
|
150
|
+
|
151
|
+
label,
|
152
|
+
|
153
|
+
button,
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
};
|
158
|
+
|
159
|
+
}
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
```
|
166
|
+
|
167
|
+
[Xamarin(PCL)]IGetText.cs(インターフェイス)
|
168
|
+
|
169
|
+
```
|
170
|
+
|
171
|
+
using System;
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
namespace XFBindTest
|
176
|
+
|
177
|
+
{
|
178
|
+
|
179
|
+
public interface IGetText
|
180
|
+
|
181
|
+
{
|
182
|
+
|
183
|
+
string Text { get; }
|
184
|
+
|
185
|
+
}
|
186
|
+
|
187
|
+
}
|
188
|
+
|
189
|
+
```
|
190
|
+
|
191
|
+
[Xamarin(iOS)]GetTextImplement.cs
|
192
|
+
|
193
|
+
```
|
194
|
+
|
195
|
+
using System;
|
196
|
+
|
197
|
+
using System.Diagnostics;
|
198
|
+
|
199
|
+
using XFBindTest.iOS;
|
200
|
+
|
201
|
+
using XCLib;
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
using System.Runtime.InteropServices;
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
[assembly: Xamarin.Forms.Dependency(typeof(GetTextImplement))]
|
210
|
+
|
211
|
+
namespace XFBindTest.iOS
|
212
|
+
|
213
|
+
{
|
214
|
+
|
215
|
+
public class GetTextImplement : IGetText
|
216
|
+
|
217
|
+
{
|
218
|
+
|
219
|
+
public GetTextImplement()
|
220
|
+
|
221
|
+
{
|
222
|
+
|
223
|
+
}
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
public string Text
|
228
|
+
|
229
|
+
{
|
230
|
+
|
231
|
+
get
|
232
|
+
|
233
|
+
{
|
234
|
+
|
235
|
+
Debug.WriteLine(XamarinTestLib.Add(2, 3));
|
236
|
+
|
237
|
+
Debug.WriteLine(XamarinTestLib.Multi(2, 3));
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
#if false
|
242
|
+
|
243
|
+
XamarinTestLib lib = new XamarinTestLib();// ここでエラー
|
244
|
+
|
245
|
+
Debug.WriteLine(lib.Add2(4, 5));
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
Debug.WriteLine(lib.CalcI(128));
|
250
|
+
|
251
|
+
Debug.WriteLine(lib.CalcF(314));
|
252
|
+
|
253
|
+
Debug.WriteLine(lib.CalcS);
|
254
|
+
|
255
|
+
#endif
|
256
|
+
|
257
|
+
return "abcdef";
|
258
|
+
|
259
|
+
}
|
260
|
+
|
261
|
+
}
|
262
|
+
|
263
|
+
}
|
264
|
+
|
265
|
+
}
|
266
|
+
|
267
|
+
```
|
268
|
+
|
269
|
+
[XCode]XamarinTestLib.h
|
270
|
+
|
271
|
+
```
|
272
|
+
|
273
|
+
#import <Foundation/Foundation.h>
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
@interface XamarinTestLib : NSObject
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
+ (int)add: (int)a para:(int)b;
|
282
|
+
|
283
|
+
+ (int)multi: (int)a para:(int)b;
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
- (int)Add2: (int)a para:(int)b;
|
288
|
+
|
289
|
+
- (int)calcI: (int)a;
|
290
|
+
|
291
|
+
- (float)calcF: (int)a;
|
292
|
+
|
293
|
+
- (NSString *)calcS;
|
294
|
+
|
295
|
+
@end
|
296
|
+
|
297
|
+
```
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
[XCode]XamarinTestLib.m
|
302
|
+
|
303
|
+
```
|
304
|
+
|
305
|
+
#import "XamarinTestLib.h"
|
306
|
+
|
307
|
+
#import <UIKit/UIKit.h>
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
@implementation XamarinTestLib
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
+ (int)add: (int)a para:(int)b
|
316
|
+
|
317
|
+
{
|
318
|
+
|
319
|
+
return (a + b);
|
320
|
+
|
321
|
+
}
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
+ (int)multi: (int)a para:(int)b
|
326
|
+
|
327
|
+
{
|
328
|
+
|
329
|
+
return (a * b);
|
330
|
+
|
331
|
+
}
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
- (int)Add2: (int)a para:(int)b
|
336
|
+
|
337
|
+
{
|
338
|
+
|
339
|
+
return a + b;
|
340
|
+
|
341
|
+
}
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
- (int)calcI: (int)a
|
346
|
+
|
347
|
+
{
|
348
|
+
|
349
|
+
return a * 2;
|
350
|
+
|
351
|
+
}
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
- (float)calcF: (int)a
|
356
|
+
|
357
|
+
{
|
358
|
+
|
359
|
+
return a / 100.0f;
|
360
|
+
|
361
|
+
}
|
362
|
+
|
363
|
+
|
364
|
+
|
365
|
+
- (NSString *)calcS
|
366
|
+
|
367
|
+
{
|
368
|
+
|
369
|
+
return @"123456";
|
370
|
+
|
371
|
+
}
|
372
|
+
|
373
|
+
@end
|
374
|
+
|
375
|
+
```
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
[ApiDefinitions.cs(Object Sharpieで生成したものを書き換えてXamarinに組み込んでいるもの)]
|
380
|
+
|
381
|
+
```
|
382
|
+
|
383
|
+
using System;
|
384
|
+
|
385
|
+
using Foundation;
|
386
|
+
|
387
|
+
using ObjCRuntime;
|
388
|
+
|
389
|
+
|
390
|
+
|
391
|
+
namespace XCLib
|
392
|
+
|
393
|
+
{
|
394
|
+
|
395
|
+
// @interface XamarinTestLib : NSObject
|
396
|
+
|
397
|
+
[BaseType (typeof(NSObject))]
|
398
|
+
|
399
|
+
interface XamarinTestLib
|
400
|
+
|
401
|
+
{
|
402
|
+
|
403
|
+
// +(int)add:(int)a para:(int)b;
|
404
|
+
|
405
|
+
[Static]
|
406
|
+
|
407
|
+
[Export ("add:para:")]
|
408
|
+
|
409
|
+
int Add (int a, int b);
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
// +(int)multi:(int)a para:(int)b;
|
414
|
+
|
415
|
+
[Static]
|
416
|
+
|
417
|
+
[Export ("multi:para:")]
|
418
|
+
|
419
|
+
int Multi (int a, int b);
|
420
|
+
|
421
|
+
|
422
|
+
|
423
|
+
// -(int)Add2:(int)a para:(int)b;
|
424
|
+
|
425
|
+
[Export("Add2:para:")]
|
426
|
+
|
427
|
+
int Add2(int a, int b);
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
// -(int)calcI:(int)a;
|
432
|
+
|
433
|
+
[Export("calcI:")]
|
434
|
+
|
435
|
+
int CalcI(int a);
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
// -(float)calcF:(int)a;
|
440
|
+
|
441
|
+
[Export("calcF:")]
|
442
|
+
|
443
|
+
float CalcF(int a);
|
444
|
+
|
445
|
+
|
446
|
+
|
447
|
+
// -(NSString *)calcS;
|
448
|
+
|
449
|
+
[Export("calcS")]
|
450
|
+
|
451
|
+
string CalcS { get; }
|
452
|
+
|
453
|
+
}
|
454
|
+
|
455
|
+
}
|
456
|
+
|
457
|
+
```
|