2013-12-11

Cross import header


WebView.h
@class ViewController; // This pre-declares ViewController, allowing this header to use pointers to ViewController, but not actually use the contents of ViewController

@interface WebView : UIWebView
{
   ViewController* viewController;
}

@end
WebView.m
#import "WebView.h"
#import "ViewController.h" // Gives full access to the ViewController class

@implementation WebView


- (void)doSomething
{
   [viewController doSomethingElse];
}

@end

2013-11-28

Custom DependencyProperty

CODE :

public class baseComboBoxItem : ComboBoxItem
    {
        public static DependencyProperty IsAllowHighlightProperty = DependencyProperty.Register("IsAllowHighlight", typeof(bool), typeof(baseComboBoxItem), new PropertyMetadata(true));  //the "true" is for custom default value, because the type is "bool"
        public baseComboBoxItem()
        {
         
        }

        public bool IsAllowHighlight
        {
            get
            {
                return (bool)base.GetValue(IsAllowHighlightProperty);
            }
            set
            {
                base.SetValue(IsAllowHighlightProperty, value);
            }
        }
    }

So, we can use IsAllowHighlight in XAML

<BC:baseComboBox x:Class="MakeMoney.BaseControls.comboColorPicker"
             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"
             xmlns:BC="clr-namespace:MakeMoney.BaseControls"
             mc:Ignorable="d"
             d:DesignHeight="300" d:DesignWidth="300"
             Width="100" Height="26" SelectionChanged="baseComboBox_SelectionChanged">  
    <BC:baseComboBoxItem Background="#FF000000" IsAllowHighlight="False"><TextBlock Text="" /></BC:baseComboBoxItem>
    <BC:baseComboBoxItem Background="#FFCCCCCC"><TextBlock Text="" /></BC:baseComboBoxItem>
    <BC:baseComboBoxItem Background="#FFDDDDDD"><TextBlock Text="" /></BC:baseComboBoxItem>
</BC:baseComboBox>

And also, for template triggers

<ControlTemplate.Triggers>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsHighlighted" Value="True"/>
                                <Condition Property="IsAllowHighlight" Value="True" />
                            </MultiTrigger.Conditions>
                            <Setter Property="Background" TargetName="Bd" Value="{StaticResource baseHighlightedBackground}"/>
                        </MultiTrigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
</ControlTemplate.Triggers>

2013-11-25

Use the image in style setting

Environment :

In resource dictionary, load image in style

When new instance apply the style, previous control who applied this style will lost the image.



Solution :

Add x:Shared="False" for style


EX:
<Style TargetType="{x:Type BC:captionButtonMin}" BasedOn="{StaticResource styleCaptionButton}" x:Shared="False">
        <Setter Property="BorderThickness" Value="1,1,1,1"/>
        <Setter Property="CornerRadius" Value="0,0,0,4"/>
        <Setter Property="Content">
            <Setter.Value>
                <Image Source="/Resources/Images/captionButtonMIN.jpg" Width="12" Margin="0,4,0,0"/>
            </Setter.Value>
        </Setter>      
    </Style>



Weird :

x:Shared does not show up from Intellisense??

2013-11-12

Get type from string and new an instance

menuItem.Tag = "namespace.class, dllname";
Type windowType = Type.GetType((string)(menuItem.Tag));
Control window = (Control)Activator.CreateInstance(windowType);
window.Show();

Store type from generic methods

public class baseMenuItem : MenuItem
    {      

        Type handleWindowType;

        public baseMenuItem()
        {
            this.Click += baseMenuItem_Click;
        }

        void baseMenuItem_Click(object sender, RoutedEventArgs e)
        {
            if (null != handleWindowType)
            {
                baseWindow win = (baseWindow)Activator.CreateInstance(handleWindowType);
                win.Show();
            }
         
            e.Handled = true;   //To prevent routed event triggered
        }

        public void AssignHandleWindow<T>() where T : baseWindow
        {
            handleWindowType = typeof(T);          
        }
    }

2013-10-29

How to declare private function in Objective-C


inside .m file, add @interface declaration


#import “MyClass.h”
@interface MyClass()
- (void) doMyPrivateFunction;
- (int) getMyMagicNumber;
@end

@implementation MyClass
….. 
@end

so that the function will be private.

2013-09-07

Remove HTML tag

Regex.Replace(row["content"].ToString(), @"<(.|\n)*?>", string.Empty);

2013-09-06

Custom Template in VisualStudio

預設template位置
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\ItemTemplates
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\ProjectTemplates
預設Custom Template位置
\\MyDocument\Visual Studio 2012\Templates
工具->選項->專案和方案->一般  (可更改位置)


TO ADD A CUSTOM PROJECT ITEM TEMPLATE TO THE ADD NEW ITEM DIALOG BOX

  1. Create or open a project in Visual Studio.
  2. Add an item to the project and modify it if you want to.
  3. Modify the code file to indicate where parameter replacement should take place. For more information, see How to: Substitute Parameters in a Template.
  4. On the File menu, click Export Template.
  5. Click Item Template, select the project that contains the item, and click Next.
  6. Select the item for which you want to create a template, and click Next.
  7. Select the assembly references to include in the template, and click Next.
  8. Type the icon file name, preview image, template name, and template description, and click Finish.
    The files for the template are added to a .zip file and copied to the ..\Users\username\Documents\Visual Studio Version\Templates\ItemTemplates\ folder.

2013-08-28

Update DataTime in SQLite

When operating DateTime type in SQLite, need to convert the date time string into specific format
yyyy-MM-dd HH:mm:ss

2013-08-18

Certificate & Provision

從MAC的KeyChain中,  鑰匙圈存取->憑証輔助程式->從憑証授權要求憑証
email : 不知有何影響, 非AppleID
一般名稱 : 在KeyChain中會顯示的名稱
要求之後
1. 產生CertificateSigningRequest.certSigningRequest 這個檔案, 這是要上傳到Apple Developer去產生cetificate的
2. 在KeyChain中會自動產生兩把Key(公用密鑰, 專用密鑰)

接著到Apple Developer, 登入後到Certificates去新增憑証
Development類型的憑証好像不能重覆?
選好憑証類型之後, 順著流程將CSR檔案上傳, 上傳完畢後即會產生.cer檔供下載
下載後double click這個檔, 即會灌入KeyChain中並與專用密鑰自動連結

接著處理Provision
一個Provision跟一個App ID對應
這裏的App ID是指在Apple Developer裏設定, 準備要開發的app
一個Provision可以包含多個憑証(每個憑証相當於對應一台開發機器)
一個Provision可以包含多台iDevice
Provision是用來安裝在iDevice上,
所以整個Certificates跟Provision的作用,
是Apple為了控制哪個開發者帳號(by Apple ID)
用了哪台機器(by Certificate)
要開發什麼app(by App IDs of Provision)
要在哪些iDevice(by Devices of Provision)上測試

生成Provision並下載之後, double-click即會安裝進XCode Origanizer裏供專案使用, 視必要會自動安裝到iDevice上去

2013-05-30

XCODE設定部份程式碼不使用ARC

1. 選擇專案,此時會出現專案設定畫面。
2. 選擇你的 Target,並切換到 Build Phases 畫面。
3. 找到 Compile Sources 這個畫面,然後選擇你要設定不使用 ARC 的程式碼
4. 按下 Enter 鍵後,會跳出一個視窗要你輸入東西,在裏面輸入 -fno-objc-arc 就可以了。