Silverlight에서 CSS 접근
.NET프로그래밍/Silverlight 3.0 2009. 12. 9. 09:59 |- 동적으로 스타일시트의 값 변경 가능
"RiaCssTestPage.html"에서 아래와 같이 코드를 수정하여 실버라이트 영역(사이즈)을 설정한다.
[RiaCssTestPage.html]
#silverlightControlHost {
height: 300px; width:300px; border:1px dotted red;
text-align:center;
}
</style>
-------------------------------------------------------------------------------------
<body>
<form id="form1" runat="server" style="height:100%">
<h3>실버라이트 영역</h3>
<div id="silverlightControlHost">
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
<param name="source" value="ClientBin/RiaCss.xap"/>
<param name="onError" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="3.0.40818.0" />
<param name="autoUpgrade" value="true" />
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40818.0" style="text-decoration:none">
<img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
</a>
</object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe>
</div>
<h3>HTML 영역</h3>
<div id="divHello" style="background-color:Yellow;">
안녕하세요...
</div>
</form>
</body>
[MainPage.xaml]
<UserControl x:Class="RiaCss.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Canvas x:Name="LayoutRoot" Background="White">
<Rectangle
x:Name="greenRect" Width="100" Height="100" Canvas.Left="50" Canvas.Top="50" Fill="Green" />
<Rectangle
x:Name="blueRect" Width="100" Height="100" Canvas.Left="150" Canvas.Top="150" Fill="Blue" />
</Canvas>
</UserControl>
[MainPage.xaml.cs]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Browser;
namespace RiaCss
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
greenRect.MouseEnter += new MouseEventHandler(greenRect_MouseEnter);
blueRect.MouseEnter += new MouseEventHandler(blueRect_MouseEnter);
}
void blueRect_MouseEnter(object sender, MouseEventArgs e)
{
//[1] HTML 페이지에 접근
HtmlDocument document = HtmlPage.Document;
//[2] HTML의 레이어(div)에 접근
if (document.GetElementById("divHello") != null)
{
//[3] 해당 요소 가져오기
HtmlElement div = document.GetElementById("divHello");
//[4] 새로운 스타일 적용
div.SetStyleAttribute("backgroundColor", "blue");
}
}
void greenRect_MouseEnter(object sender, MouseEventArgs e)
{
//[1] HTML 페이지에 접근
HtmlDocument document = HtmlPage.Document;
//[2] HTML의 레이어(div)에 접근
if (document.GetElementById("divHello") != null)
{
//[3] 해당 요소 가져오기
HtmlElement div = document.GetElementById("divHello");
//[4] 새로운 스타일 적용
div.SetStyleAttribute("backgroundColor", "green");
}
}
}
}
'.NET프로그래밍 > Silverlight 3.0' 카테고리의 다른 글
Silverlight에서 쿼리스트링 정보 얻기 (0) | 2009.12.09 |
---|---|
Silverlight에서 JavaScript 접근 (0) | 2009.12.09 |
Silverlight에서 HTML 접근 (0) | 2009.12.08 |
로컬 커넥션 (0) | 2009.12.08 |
Navigation Framework 사용 (0) | 2009.12.08 |