这是xaml:
<Page.Resources>
<ControlTemplate x:Key="WeddingButtonBigTemplate" TargetType="Button">
<Grid>
<Image x:Name="imgNormal" Source="../Images/Married_button2.png"/>
<TextBlock x:Name="textBlock2" Style="{StaticResource RegularBlueSpecialBoldText}" LineHeight="28" LineStackingStrategy="BlockLineHeight" HorizontalAlignment="Center" Margin="10,30,10,70" TextWrapping="Wrap" TextAlignment="Center" VerticalAlignment="Stretch" >
<Run FontSize="20" Text="The event of"></Run>
<Run FontSize="28" Text="{DynamicResource strBride}"></Run>
</TextBlock>
</Grid>
</ControlTemplate>
</Page.Resources>
<Grid HorizontalAlignment="Center" VerticalAlignment="Top" Width="1000">
<Button x:Name="btnWedding" HorizontalAlignment="Left" Margin="10,20,0,-49" VerticalAlignment="Top" Template="{StaticResource WeddingButtonBigTemplate}" Foreground="#FF2B4072" Width="380" Click="btnClick" />
</Grid>
Run Code Online (Sandbox Code Playgroud)
我想要访问名为的TextBlock textBlock2.
我试图覆盖OnApplyTemplate但是得到了null.
我试过了:
Grid gridInTemplate = (Grid)btnWedding.Template.FindName("grid", btnWedding);
var ct0 = btnWedding.Template.FindName("textBlock2", btnWedding);
var ct1 = btnWedding.FindName("textBlock2");
var ct2 = btnWedding.FindResource("textBlock2");
Run Code Online (Sandbox Code Playgroud)
gridInTemplate为null(从MSDN获取的样本).
当然,ct#都是null.
我在这里错过了什么?
我想构建一个Control支持Opcacity属性的派生类.
这个控件既可以托管文本也可以托管图像,并且可以将它们淡出和放入.
这是我的代码:
internal class FadeControl : Control
{
private int opacity = 100;
public FadeControl()
{
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
}
public int Opacity
{
get
{
return opacity;
}
set
{
if (value > 100) opacity = 100;
else if (value < 1) opacity = 1;
else opacity = value;
if (Parent != null)
Parent.Invalidate(Bounds, true);
}
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle = cp.ExStyle | 0x20;
return cp; …Run Code Online (Sandbox Code Playgroud) 我想建立一个代理服务器来处理本地请求.
例如 - 捕获Web浏览器打印请求并将它们发送到适当的LAN打印机.
到目前为止,我的想法是在Windows服务中托管FiddlerCore引擎.
这是我的代码:
private static void Main()
{
FiddlerApplication.OnNotification += (sender, e) => Console.WriteLine("** NotifyUser: " + e.NotifyString);
FiddlerApplication.Log.OnLogString += (sender, e) => Console.WriteLine("** LogString: " + e.LogString);
FiddlerApplication.BeforeRequest += oSession => { Console.WriteLine("Before request for:\t" + oSession.fullUrl); oSession.bBufferResponse = true; ParseRequest(oSession); };
FiddlerApplication.BeforeResponse += oSession => Console.WriteLine("{0}:HTTP {1} for {2}", oSession.id, oSession.responseCode, oSession.fullUrl);
FiddlerApplication.AfterSessionComplete += oSession => Console.WriteLine("Finished session:\t" + oSession.fullUrl);
Console.CancelKeyPress += Console_CancelKeyPress;
Console.WriteLine("Starting FiddlerCore...");
CONFIG.IgnoreServerCertErrors = true;
FiddlerApplication.Startup(8877, true, true);
Console.WriteLine("Hit CTRL+C to end …Run Code Online (Sandbox Code Playgroud) 试图切换MarkerClusterer(V3)的可见性:
var hydrantsShowing = true;
function ToggleHydrants() {
var markers = hydrantsClusterer.getMarkers();
for (var i = 0; i < markers.length; i++) {
markers[i].setVisible(!hydrantsShowing);
}
hydrantsShowing = !hydrantsShowing;
}
Run Code Online (Sandbox Code Playgroud)
标记切换但有两个问题:
1.地图必须平移一点才能发生变化.
2.即使标记不可见,MarkerClusterer图标(带有数字)也始终存在.
我也尝试过使用setMap方法,但行为类似:
var hydrantsShowing = true;
function ToggleHydrants() {
var markers = hydrantsClusterer.getMarkers();
if (hydrantsShowing) {
for (var i = 0; i < markers.length; i++) {
markers[i].setMap(null);
}
}
else {
for (var i = 0; i < markers.length; i++) {
markers[i].setMap(gmap);
}
}
hydrantsShowing = !hydrantsShowing;
}
Run Code Online (Sandbox Code Playgroud) 我试图在没有DirectionsRenderer.
这是我的代码:
var map;
var directionsService;
function initialize() {
var mapOptions = { mapTypeId: google.maps.MapTypeId.ROADMAP }
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
directionsService = new google.maps.DirectionsService();
calcRoute();
}
function calcRoute() {
var request = {
origin: '??? ???',
destination: '??? ???',
travelMode: google.maps.TravelMode.WALKING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
map.fitBounds(directionResult.routes[0].bounds);
createPolyline(response);
}
});
}
function createPolyline(directionResult) {
var line = new google.maps.Polyline({
path: directionResult.routes[0].overview_path,
strokeColor: '#FF0000',
strokeOpacity: 0.5,
strokeWeight: 4
});
line.setMap(map);
for (var i …Run Code Online (Sandbox Code Playgroud) 我有一个可以被多种原因锁定的系统.
这是静态类,负责保持锁定状态:
internal static class Locker
{
private static ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
internal static bool LockedByReason1 { get; set; }
internal static bool LockedByReason2 { get; set; }
internal static bool LockedByReason3 { get; set; }
internal static bool Locked
{
get
{
log.DebugFormat("LockedByReason1: {0}, LockedByReason2: {1}, LockedByReason3: {2}", LockedByReason1, LockedByReason2, LockedByReason3);
return LockedByReason1 || LockedByReason2 || LockedByReason3;
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是业务逻辑中的代码:
Locker.LockedByReason1 = false;
if (Locker.Locked)
log.Info("Unlocking system...");
else
log.Info("Not unlocking system");
Run Code Online (Sandbox Code Playgroud)
我的日志文件显示此文本:
2014-06-06 10:54:31,765 DEBUG Client.Utils.Locker - …Run Code Online (Sandbox Code Playgroud) c# ×4
c#-4.0 ×1
controls ×1
fading ×1
fiddler ×1
fiddlercore ×1
google-maps ×1
opacity ×1
proxy ×1
static ×1
visibility ×1
wpf ×1